2024-04-20 01:43:52 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
See also:
|
2024-04-27 23:33:08 +00:00
|
|
|
|
|
|
|
- https://inotify-simple.readthedocs.io/en/latest/#gracefully-exit-a-blocking-read
|
2024-04-20 01:43:52 +00:00
|
|
|
'''
|
|
|
|
import threading
|
|
|
|
|
2024-04-27 23:33:08 +00:00
|
|
|
from execlog.event import Event
|
|
|
|
|
2024-04-20 01:43:52 +00:00
|
|
|
|
2024-04-27 23:33:08 +00:00
|
|
|
class Listener[E: Event](threading.Thread):
|
2024-04-29 00:21:33 +00:00
|
|
|
'''
|
|
|
|
Implements a file system watcher.
|
|
|
|
'''
|
2024-04-27 23:33:08 +00:00
|
|
|
def __init__(self, router: 'Router[E]'):
|
2024-04-20 01:43:52 +00:00
|
|
|
'''
|
|
|
|
Parameters:
|
2024-04-27 23:33:08 +00:00
|
|
|
router: associated Router instance that events should be passed to
|
2024-04-20 01:43:52 +00:00
|
|
|
'''
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
self.router = router
|
|
|
|
|
|
|
|
def listen(self):
|
2024-04-27 23:33:08 +00:00
|
|
|
'''
|
|
|
|
Register a new listener endpoint
|
|
|
|
'''
|
2024-04-20 01:43:52 +00:00
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
def run(self):
|
2024-04-27 23:33:08 +00:00
|
|
|
'''
|
|
|
|
Begin listening for events. Typically a blocking loop that passes events to
|
|
|
|
attached Router.
|
|
|
|
'''
|
2024-04-20 01:43:52 +00:00
|
|
|
raise NotImplementedError
|
2024-04-28 21:35:04 +00:00
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
'''
|
|
|
|
Begin listening for events. Typically a blocking loop that passes events to
|
|
|
|
attached Router.
|
|
|
|
'''
|
|
|
|
raise NotImplementedError
|