开发者

pyinotify asyncnotifier thread question

开发者 https://www.devze.com 2023-01-20 17:26 出处:网络
I\'m confused about how asyncnotifier works.开发者_Python百科 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

I'm confused about how asyncnotifier works.开发者_Python百科 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.


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消