watchdog icon indicating copy to clipboard operation
watchdog copied to clipboard

Feature request – gevent compatibility

Open davidkhess opened this issue 10 years ago • 14 comments

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.

davidkhess avatar Mar 24 '15 02:03 davidkhess

this would be nice to have, i'm still digging into it but this is blocking me :+1:

fuag15 avatar Mar 26 '15 18:03 fuag15

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.

davidkhess avatar Mar 26 '15 18:03 davidkhess

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

davidkhess avatar Mar 26 '15 19:03 davidkhess

+1

richgong avatar Mar 26 '15 22:03 richgong

+1

gabrielgrant avatar Apr 01 '15 17:04 gabrielgrant

Not sure you've had the same issue as me, but this seems to have fixed it for me: e4eebae522e2e6fc9448de12a8a15e924ed684e9

csantosbh avatar Jul 15 '15 02:07 csantosbh

I've run into this issue and created watchdog_gevent. Hopefully it's of use to some of you.

Bogdanp avatar Dec 08 '17 20:12 Bogdanp

@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 avatar Dec 11 '17 15:12 davidkhess

@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

Bogdanp avatar Dec 11 '17 15:12 Bogdanp

The problem I ran into was the Flask reloader. Does Flask have to be modified to benefit from your package?

davidkhess avatar Dec 11 '17 15:12 davidkhess

Ah, I misunderstood. Yes, it probably does.

Bogdanp avatar Dec 11 '17 15:12 Bogdanp

What is the state of that issue with watchdog 0.10.1?

BoboTiG avatar Feb 01 '20 11:02 BoboTiG

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.

ddorian avatar Sep 03 '23 12:09 ddorian