Python - 线程 pyinotify 输出。最好写入文件或字符串
我有一个运行线程的 pyinotify 观察程序,称为一个单独的类,目前它只是在终端窗口中打印其发现,如果我希望我的脚本根据这些更改执行操作,我最好:
A)修改数组对于每个通知
B)写入 /tmp 中的文件并从我的主脚本中获取它?
c)放弃编程
任何意见
,感谢斯图尔特的
I have a pyinotify watcher running threaded, called as a separate class, at the moment it just prints its discoveries in a terminal window, if I wanted my script to make an action based on those changes am I better to:
A) modify an array with each notification
B) write to a file in /tmp and fetch it from my main script?
c) give up programming
thanks for any input,
Stewart
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在在发现更改的线程中使用changes.put,在应该对这些更改执行操作的线程中使用changes.get(还有其他几个有用的方法) 队列
您应该检查一下 - 另请注意,根据文档,该模块在 Python 3 中已重命名为
queue
(全部小写)。队列本质上是线程安全的,因此通常是在 Python 中安排线程之间合作的最佳方式。and now use
changes.put
in the thread that discover the changes,changes.get
in the thread that is supposed to act on those changes (there are several other useful methods in Queuethat you should check -- also note, per the docs, that the module's renamed to
queue
, all lowercase, in Python 3). Queues are intrinsically thread-safe and therefore often the best way to arrange cooperation among threads in Python.