Skip to content

Instantly share code, notes, and snippets.

@MaZderMind
Created February 2, 2016 23:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaZderMind/2786a02fbf7c45e6aa55 to your computer and use it in GitHub Desktop.
Save MaZderMind/2786a02fbf7c45e6aa55 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys, gi, signal, pyinotify
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GObject, GLib
# init GObject & Co. before importing local classes
GObject.threads_init()
Gst.init([])
def handle_read_callback(notifier):
"""
Just stop receiving IO read events after the first
iteration (unrealistic example).
"""
print('handle_read callback'+str(notifier))
def process_events(source, condition, notifier):
print('process_events')
notifier.process_events()
while notifier.check_events():
notifier.read_events()
notifier.process_events()
return True
def main():
signal.signal(signal.SIGINT, signal.SIG_DFL)
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(
wm,
timeout=10,
default_proc_fun=handle_read_callback)
wm.add_watch('/tmp', pyinotify.ALL_EVENTS)
GLib.io_add_watch(notifier._fd, GLib.IO_IN, process_events, notifier)
mainloop = GObject.MainLoop()
try:
mainloop.run()
except KeyboardInterrupt:
print('Terminated via Ctrl-C')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment