Created
February 2, 2016 23:30
-
-
Save MaZderMind/2786a02fbf7c45e6aa55 to your computer and use it in GitHub Desktop.
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
#!/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