我是 python 新手,我正在尝试使用 pygtk 将 pyinotify 与 GUI 界面结合使用。我有两个类,我的 gtk 类没有做太多事情,只显示内容,另一个类处理监视。
当我单独运行它们时,它们会完成它们的工作,但是当我尝试从另一个类加载 gtk 类时,它只运行 gtk 类,监视器类仅在我退出 GUI 时运行。如果我评论最后一行,监视器运行正常。我认为“myGTK.main”阻塞了整个过程。有什么我可以做的吗?
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()
谢谢。
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.
发布评论
评论(1)
根据评论,解决方案似乎是在
脚本顶部附近添加。有关使用 pygtk 线程的此信息以及其他有用信息可以在 此常见问题解答。
Per the comments, the solution appears to be to add
near the top of the script. This, and other useful information about using threads with pygtk can be found in this faq.