Python - 线程 pyinotify 输出。最好写入文件或字符串

发布于 2024-09-13 05:16:40 字数 185 浏览 0 评论 0原文

我有一个运行线程的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残花月 2024-09-20 05:16:43
import Queue
changes = Queue.Queue()

现在在发现更改的线程中使用changes.put,在应该对这些更改执行操作的线程中使用changes.get(还有其他几个有用的方法) 队列
您应该检查一下 - 另请注意,根据文档,该模块在 Python 3 中已重命名为 queue(全部小写)。队列本质上是线程安全的,因此通常是在 Python 中安排线程之间合作的最佳方式。

import Queue
changes = Queue.Queue()

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 Queue
that 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文