Skip to content

Commit 79a57e3

Browse files
ultrabugajdavis
authored andcommitted
enhanced gevent doc with code example wrt mongodb#290
1 parent e57ed9d commit 79a57e3

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

doc/examples/gevent.rst

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,30 @@ on greenlets instead of threads.
1919

2020
Consideration on gevent's hub termination
2121
-----------------------------------------
22+
PyMongo uses threads to monitor your servers' topology and to handle
23+
graceful reconnections.
24+
2225
When shutting down your application gracefully, your code be may waiting
2326
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 !
27+
28+
This may become a **blocking operation** because monkey-patched threads
29+
are considered as greenlets and this could prevent your application
30+
to exit properly. You therefore **must close or dereference** any active
31+
MongoClient object before exiting !
32+
33+
Code example, this function is called when your application is asked
34+
to exit or gracefully reload itself by receiving a SIGHUP signal:
35+
36+
.. code-block:: python
37+
38+
import signal
39+
40+
def graceful_reload(signum, traceback):
41+
"""Explicitly close our connection
42+
"""
43+
client.close()
44+
45+
signal.signal(signal.SIGHUP, graceful_reload)
2846
2947
**uWSGI** applications using the ``gevent-wait-for-hub`` option are directly
3048
affected by this behaviour.

0 commit comments

Comments
 (0)