1

I'm newbie in python and I'm trying to use pyinotify with a GUI interface using pygtk. I have two classes, my gtk class which doesn't do much, only displays stuff, and a class that handles the monitoring.

When I run them separately they do their work but when I try to load the gtk class from the other one, it only runs the gtk class, the monitor class only runs when I exit the GUI. If I comment the last line the monitor runs fine. I think the "myGTK.main" is blocking the whole process. Is there anything I can do?

pyinotify.ProcessEvent.__init__(self)
self.notifier = pyinotify.ThreadedNotifier(self.watch_manager, self)    
self.watch_manager.add_watch('/test', pyinotify.IN_CREATE, rec=True)
self.notifier.start()
self.myGTK.main()

Thanks.

lcuz
  • 113
  • 1
  • 7
  • Have you looked at http://faq.pygtk.org/index.py?file=faq20.006.htp&req=show ? How does the structure of your code compare to the example code posted there? Do you use `gobject.threads_init()` and was your pygtk compiled with the --enable-threads flag? – unutbu May 20 '10 at 20:51
  • Great link unutbu, I've just put "gobject.threads_init()" as the FAQ said and everything worked fine. Thank you. – lcuz May 20 '10 at 22:21
  • Great! glad it worked for you. – unutbu May 21 '10 at 11:35

1 Answers1

4

Per the comments, the solution appears to be to add

gobject.threads_init()

near the top of the script. This, and other useful information about using threads with pygtk can be found in this faq.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677