Skip to content

Commit e57ed9d

Browse files
ultrabugajdavis
authored andcommitted
document gevent monkey patching side effect
when terminating gevent's hub and waiting for remaining greenlets
1 parent 5c53223 commit e57ed9d

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

doc/examples/gevent.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ PyMongo uses thread and socket functions from the Python standard library.
1616
Gevent's monkey-patching replaces those standard functions so that PyMongo
1717
does asynchronous I/O with non-blocking sockets, and schedules operations
1818
on greenlets instead of threads.
19+
20+
Consideration on gevent's hub termination
21+
-----------------------------------------
22+
When shutting down your application gracefully, your code be may waiting
23+
for any remaining greenlet to terminate before exiting.
24+
Because monkey-patched threads are greenlets and PyMongo uses quite a lot
25+
of them, this may become a **blocking operation** and may prevent your
26+
application to exit properly. You therefore must close (or dereference)
27+
any active MongoClient object before exiting !
28+
29+
**uWSGI** applications using the ``gevent-wait-for-hub`` option are directly
30+
affected by this behaviour.

0 commit comments

Comments
 (0)