Created
September 25, 2015 02:10
-
-
Save Fingel/67b307821401282a96ac to your computer and use it in GitHub Desktop.
Using pyinotify with python 3 asyncio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyinotify | |
import asyncio | |
class EventHandler(pyinotify.ProcessEvent): | |
def process_IN_CREATE(self, event): | |
if not event.dir: | |
print("Got new file: ", event.pathname) | |
wm = pyinotify.WatchManager() # Watch Manager | |
mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE # watched events | |
loop = asyncio.get_event_loop() | |
notifier = pyinotify.AsyncioNotifier(wm, loop, default_proc_fun=EventHandler()) | |
wdd = wm.add_watch('.', mask, rec=True, auto_add=True) | |
try: | |
loop.run_forever() | |
except: | |
print('\nshutting down...') | |
loop.stop() | |
notifier.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment