From 20c11396324755e96f02c4b60a91dd7820b9741a Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Fri, 27 Nov 2020 13:12:34 +0100 Subject: [PATCH] inotify: cleanup descriptor when done --- src/documents/management/commands/document_consumer.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/documents/management/commands/document_consumer.py b/src/documents/management/commands/document_consumer.py index b738f001b..295da4f5c 100644 --- a/src/documents/management/commands/document_consumer.py +++ b/src/documents/management/commands/document_consumer.py @@ -137,12 +137,13 @@ class Command(BaseCommand): f"Using inotify to watch directory for changes: {directory}") inotify = INotify() - inotify.add_watch(directory, flags.CLOSE_WRITE | flags.MOVED_TO) + descriptor = inotify.add_watch(directory, flags.CLOSE_WRITE | flags.MOVED_TO) try: while not self.stop_flag: for event in inotify.read(timeout=1000, read_delay=1000): file = os.path.join(directory, event.name) - if os.path.isfile(file): - _consume(file) + _consume(file) except KeyboardInterrupt: pass + + inotify.rm_watch(descriptor)