pyinotify asyncnotifier 线程问题
我对 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AsyncNotifier 不使用线程,它使用异步套接字处理程序循环。
如果您正在谈论 ThreadedNotifier,那么每个回调似乎都是在每个通知程序的同一个线程中调用的。
这意味着即使您有多个
EventHandlers
向某个WatchManager
注册,它们也会从同一线程发出回调。我找不到明确记录的位置,但从 ThreadedNotifier.loop() 方法生成的文档中似乎隐含了这一点,其中显示:
...我认为它的意思是它在单个线程中作为一个相当简单的循环运行,从该循环发出回调。
我尝试过简单地打印
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 someWatchManager
, 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:...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.)