From 0ba39aa71b9b19a0828920fc479eadce2abf3b44 Mon Sep 17 00:00:00 2001 From: Sergey Shepelev Date: Wed, 21 Oct 2020 10:49:26 +0300 Subject: [PATCH] patcher: [py27] recursion error in pytest/python2.7 installing register_at_fork https://github.com/eventlet/eventlet/issues/660 https://github.com/getsentry/sentry-python/pull/880 Could not reproduce problem without pytest, so normal production code was probably safe. --- eventlet/patcher.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/eventlet/patcher.py b/eventlet/patcher.py index 030fa5478c..652e3f8021 100644 --- a/eventlet/patcher.py +++ b/eventlet/patcher.py @@ -1,5 +1,7 @@ import imp +import os import sys +#_os = original('os') import eventlet import six @@ -229,7 +231,6 @@ 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 @@ -298,6 +299,7 @@ def monkey_patch(**on): # tell us whether or not we succeeded pass + _threading = original('threading') imp.acquire_lock() try: for name, mod in modules_to_patch: @@ -313,10 +315,9 @@ def monkey_patch(**on): if hasattr(orig_mod, attr_name): delattr(orig_mod, attr_name) - _os = original('os') - if name == 'threading' and hasattr(_os, 'register_at_fork'): + if name == 'threading' and hasattr(os, 'register_at_fork'): def fix_threading_active( - _global_dict=original('threading').current_thread.__globals__, + _global_dict=_threading.current_thread.__globals__, _patched=orig_mod ): _prefork_active = [None] @@ -328,7 +329,7 @@ def before_fork(): def after_fork(): _global_dict['_active'] = _prefork_active[0] - _os.register_at_fork( + os.register_at_fork( before=before_fork, after_in_parent=after_fork) fix_threading_active()