Skip to content
Snippets Groups Projects
Commit 7baf1584 authored by ale's avatar ale
Browse files

fixes to the linux inotify thread; add signal handlers for clean exit

parent 33623d9b
No related branches found
No related tags found
No related merge requests found
...@@ -60,6 +60,15 @@ def run_client(server_url, music_dir, api_key, run_once, bwlimit): ...@@ -60,6 +60,15 @@ def run_client(server_url, music_dir, api_key, run_once, bwlimit):
else: else:
log.warn('inotify/fsevents support not enabled on this platform') log.warn('inotify/fsevents support not enabled on this platform')
def _cleanup(signum, frame):
if enable_watcher:
log.info('stopping watcher...')
wtch.stop()
log.info('got signal %d, exiting...' % signum)
upl.stop()
signal.signal(signal.SIGINT, _cleanup)
signal.signal(signal.SIGTERM, _cleanup)
upl.run() upl.run()
......
...@@ -4,16 +4,21 @@ import pyinotify ...@@ -4,16 +4,21 @@ import pyinotify
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class Watcher(object): class Watcher(pyinotify.ProcessEvent):
def __init__(self, base, queue): def __init__(self, base, queue):
self.queue = queue
self.wm = pyinotify.WatchManager() self.wm = pyinotify.WatchManager()
self.wm.add_watch('/tmp', pyinotify.IN_CLOSE_WRITE, rec=True)
self.notifier = pyinotify.ThreadedNotifier(self.wm, self) self.notifier = pyinotify.ThreadedNotifier(self.wm, self)
self.notifier.setDaemon(True) self.notifier.setDaemon(True)
self.notifier.start() self.notifier.start()
self.wm.add_watch(base, pyinotify.IN_CLOSE_WRITE, rec=True)
def stop(self):
self.notifier.stop()
def process_IN_CLOSE(self, event): def process_IN_CLOSE(self, event):
if event.pathname.lower().endswith('.mp3'): if event.pathname.lower().endswith('.mp3'):
log.debug('event in %s: %x' % (event.pathname, event.mask)) log.debug('event in %s: %x' % (event.pathname, event.mask))
self.queue.put(event.pathname) self.queue.put(event.pathname)
...@@ -99,3 +99,7 @@ class Uploader(object): ...@@ -99,3 +99,7 @@ class Uploader(object):
finally: finally:
log.debug('uploader thread exiting') log.debug('uploader thread exiting')
self.db.close() self.db.close()
def stop(self):
self.queue.put(None)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment