Skip to content

Commit 4edbd03

Browse files
committed
More info about gevent monkey patching effects.
1 parent 79a57e3 commit 4edbd03

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

doc/conf.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
# Add any Sphinx extension module names here, as strings. They can be extensions
1515
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
1616
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.coverage',
17-
'sphinx.ext.todo', 'doc.mongo_extensions']
17+
'sphinx.ext.todo', 'doc.mongo_extensions',
18+
'sphinx.ext.intersphinx']
1819

1920
# Add any paths that contain templates here, relative to this directory.
2021
templates_path = ['_templates']
@@ -160,3 +161,7 @@
160161

161162
# If false, no module index is generated.
162163
#latex_use_modindex = True
164+
165+
intersphinx_mapping = {
166+
'gevent': ('http://www.gevent.org/', None),
167+
}

doc/contributors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@ The following is a list of people who have contributed to
7777
- Heewa Barfchin (heewa)
7878
- Anna Herlihy (aherlihy)
7979
- Len Buckens (buckensl)
80+
- ultrabug

doc/examples/gevent.rst

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,35 @@ 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.
1919

20-
Consideration on gevent's hub termination
21-
-----------------------------------------
22-
PyMongo uses threads to monitor your servers' topology and to handle
23-
graceful reconnections.
20+
Avoid blocking in Hub.join
21+
--------------------------
2422

25-
When shutting down your application gracefully, your code be may waiting
26-
for any remaining greenlet to terminate before exiting.
23+
By default, PyMongo uses threads to discover and monitor your servers' topology
24+
(see :ref:`health-monitoring`). If you execute ``monkey.patch_all()`` when
25+
your application first begins, PyMongo automatically uses greenlets instead
26+
of threads.
2727

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 !
28+
When shutting down, if your application calls :meth:`~gevent.hub.Hub.join` on
29+
Gevent's :class:`~gevent.hub.Hub` without first terminating these background
30+
greenlets, the call to :meth:`~gevent.hub.Hub.join` blocks indefinitely. You
31+
therefore **must close or dereference** any active
32+
:class:`~pymongo.mongo_client.MongoClient` before exiting.
3233

33-
Code example, this function is called when your application is asked
34-
to exit or gracefully reload itself by receiving a SIGHUP signal:
34+
An example solution to this issue in some application frameworks is a signal
35+
handler to end background greenlets when your application receives SIGHUP:
3536

3637
.. code-block:: python
3738
3839
import signal
3940
4041
def graceful_reload(signum, traceback):
41-
"""Explicitly close our connection
42-
"""
42+
"""Explicitly close some global MongoClient object."""
4343
client.close()
4444
4545
signal.signal(signal.SIGHUP, graceful_reload)
4646
47-
**uWSGI** applications using the ``gevent-wait-for-hub`` option are directly
48-
affected by this behaviour.
47+
Applications using uWSGI prior to 1.9.16 are affected by this issue,
48+
or newer uWSGI versions with the ``-gevent-wait-for-hub`` option.
49+
See `the uWSGI changelog for details
50+
<http://uwsgi-docs.readthedocs.org/en/latest/Changelog-1.9.16.html#important-change-in-the-gevent-plugin-shutdown-reload-procedure>`_.
51+

doc/examples/high_availability.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ milliseconds of the closest member's ping time.
302302

303303
.. _localThreshold: http://docs.mongodb.org/manual/reference/mongos/#cmdoption--localThreshold
304304

305+
.. _health-monitoring:
306+
305307
Health Monitoring
306308
'''''''''''''''''
307309

0 commit comments

Comments
 (0)