pyinotify asyncnotifier 线程问题

发布于 2024-09-27 12:36:44 字数 110 浏览 7 评论 0原文

我对 asyncnotifier 的工作原理感到困惑。通知程序中到底线程化了什么?只有观察者线程吗?或者处理程序函数的每个回调是否在其自己的线程上运行?

该文档基本上没有提及该类的具体细节。

I'm confused about how asyncnotifier works. What exactly is threaded in the notifier? Is the just the watcher threaded? Or does each of the callbacks to the handler functions run on its own thread?

The documentation says essentially nothing about the specifics of the class.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

醉生梦死 2024-10-04 12:36:44

AsyncNotifier 不使用线程,它使用异步套接字处理程序循环。

如果您正在谈论 ThreadedNotifier,那么每个回调似乎都是在每个通知程序的同一个线程中调用的。

这意味着即使您有多个 EventHandlers 向某个 WatchManager 注册,它们也会从同一线程发出回调。

我找不到明确记录的位置,但从 ThreadedNotifier.loop() 方法生成的文档中似乎隐含了这一点,其中显示:

事件最多每 min(read_freq, timeout) 秒读取一次,并且仅当要读取的事件大小 >= 阈值时才读取。

...我认为它的意思是它在单个线程中作为一个相当简单的循环运行,从该循环发出回调。

我尝试过简单地打印 threading.current_thread()在回调中,并验证这一点。

(如果您认为有必要,您可以随时提交问题来请求更具体的文档。)

The AsyncNotifier doesn't use threading, it uses the asynchronous socket handler loop.

If you're talking about the ThreadedNotifier, then each callback seems to be called in the same thread per notifier.

This means that even if you have several EventHandlers registered with some WatchManager, they will all issue callbacks from the same thread.

I can't find where this is explicitly documented, but seems implicit from the generated documentation for the ThreadedNotifier.loop() method, where it says:

Events are read only once time every min(read_freq, timeout) seconds at best and only if the size of events to read is >= threshold.

...which I took to mean it operates as a fairly simple loop in a single thread, issuing callbacks from that loop.

I have experimented by simply printing the result of threading.current_thread() in the callbacks, and it verifies this.

(You could always file an issue to request more specific documentation if you think that's warranted.)

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