watchdog
watchdog copied to clipboard
Feature request – gevent compatibility
It would be nice if watchdog was gevent compatible.
Problems I've run into so far:
- There is an os.read() in notify_c.py that is blocking – would need to use gevent.os.tp_read() instead.
- There's an indication that DelayedQueue is not working right. Not sure what is wrong there.
this would be nice to have, i'm still digging into it but this is blocking me :+1:
Nice to have some company. :-)
FYI, my use case is trying to use Flask reloader. If you have watchdog installed the latest Flask automatically tries to use it – and if you are using gevent, it promptly locks up.
BTW, if anybody is looking for a strategy on how to support gevent, psycopg2's approach is pretty good:
http://initd.org/psycopg/docs/advanced.html#support-for-coroutine-libraries
Basically, if a callback gets registered, then the framework switches to non-blocking I/O and passes the responsibility for waiting on the I/O to the callback.
Psycogreen is an example of a module that you use with psycopg2 that provides the necessary callback to make gevent happy.
https://bitbucket.org/dvarrazzo/psycogreen
+1
+1
Not sure you've had the same issue as me, but this seems to have fixed it for me: e4eebae522e2e6fc9448de12a8a15e924ed684e9
I've run into this issue and created watchdog_gevent. Hopefully it's of use to some of you.
@Bogdanp nice work. Is that a drop in replacement so that other tools that use watchdog work with it transparently? Or do they have to be coded to specifically use your package?
@davidkhess It's drop-in. You from watchdog_gevent import Observer and it will return the best observer for the current platform. If gevent is available and threading is monkeypatched then it will return a GeventObserver, otherwise it will fall back to the observer returned by watchdog itself. Here's how I ended up using it in one of my projects:
https://github.com/Bogdanp/dramatiq/commit/ebf6e877f5e61bc6a707af575e7c1a95f35e3be7
The problem I ran into was the Flask reloader. Does Flask have to be modified to benefit from your package?
Ah, I misunderstood. Yes, it probably does.
What is the state of that issue with watchdog 0.10.1?
It's still broken on Flask 2.3 watchdog 3 gevent 22.10.2. You need to use app.run(reloader_type="stat") to disable it.