Skip to content

Instantly share code, notes, and snippets.

@Fingel
Created September 25, 2015 02:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Fingel/67b307821401282a96ac to your computer and use it in GitHub Desktop.
Save Fingel/67b307821401282a96ac to your computer and use it in GitHub Desktop.
Using pyinotify with python 3 asyncio
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