Skip to content

Commit

Permalink
patcher: [py27] recursion error in pytest/python2.7 installing regist…
Browse files Browse the repository at this point in the history
…er_at_fork

#660
getsentry/sentry-python#880

Could not reproduce problem without pytest, so normal production code was probably safe.
  • Loading branch information
temoto committed Oct 22, 2020
1 parent 7b1aa58 commit 9f4c3d6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions eventlet/patcher.py
@@ -1,5 +1,11 @@
import imp
import sys
try:
# Only for this purpose, it's irrelevant if `os` was already patched.
# https://github.com/eventlet/eventlet/pull/661
from os import register_at_fork
except ImportError:
register_at_fork = None

import eventlet
import six
Expand Down Expand Up @@ -298,6 +304,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:
Expand All @@ -313,10 +320,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 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]
Expand All @@ -328,7 +334,7 @@ def before_fork():
def after_fork():
_global_dict['_active'] = _prefork_active[0]

_os.register_at_fork(
register_at_fork(
before=before_fork,
after_in_parent=after_fork)
fix_threading_active()
Expand Down

0 comments on commit 9f4c3d6

Please sign in to comment.