summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoffrey Thomas <geofft@twosigma.com>2017-08-25 15:09:06 -0400
committerSergey Shepelev <temotor@gmail.com>2017-08-26 10:58:58 +0300
commitb756447bab51046dfc6f1e0e299cc997ab343701 (patch)
tree368dec63aaad0530e79db46f18759301a726a894
parent8b88cbebe5cc0463b7531b59dc255e36b9e498df (diff)
downloadeventlet-patcher-gethub-401.tar.gz
patcher: workaround for monotonic "no suitable implementation"patcher-gethub-401
In some cases -- notably with Python 2.7.13 and the default hub -- the process of importing the hub involves calling code in a module we monkey-patch. This leads to recursive imports: the first eventlet function will call get_hub(), which will try to import the hub, which will call a monkey-patched module, which will call get_hub() and try to import the hub again. To avoid this, make sure the hub is fully imported before monkey-patching anything. https://github.com/eventlet/eventlet/issues/401
-rw-r--r--AUTHORS1
-rw-r--r--eventlet/patcher.py11
2 files changed, 12 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
index 790998b..af77252 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -151,3 +151,4 @@ Thanks To
* Feng
* Aayush Kasurde
* Linbing
+* Geoffrey Thomas
diff --git a/eventlet/patcher.py b/eventlet/patcher.py
index a929f7f..82a9cee 100644
--- a/eventlet/patcher.py
+++ b/eventlet/patcher.py
@@ -1,6 +1,7 @@
import imp
import sys
+import eventlet
from eventlet.support import six
@@ -222,6 +223,16 @@ def monkey_patch(**on):
It's safe to call monkey_patch multiple times.
"""
+
+ # Workaround for import cycle observed as following in monotonic
+ # RuntimeError: no suitable implementation for this system
+ # see https://github.com/eventlet/eventlet/issues/401#issuecomment-325015989
+ #
+ # Make sure the hub is completely imported before any
+ # monkey-patching, or we risk recursion if the process of importing
+ # the hub calls into monkey-patched modules.
+ eventlet.hubs.get_hub()
+
accepted_args = set(('os', 'select', 'socket',
'thread', 'time', 'psycopg', 'MySQLdb',
'builtins', 'subprocess'))