diff --git a/ddtrace/internal/forksafe.py b/ddtrace/internal/forksafe.py index 6b311de6025..d9cdb817cea 100644 --- a/ddtrace/internal/forksafe.py +++ b/ddtrace/internal/forksafe.py @@ -8,6 +8,7 @@ import weakref from ddtrace.internal.module import ModuleWatchdog +from ddtrace.internal.utils.formats import asbool from ddtrace.vendor import wrapt @@ -39,7 +40,8 @@ def wrapped_reinit(f, args, kwargs): wrap(module.reinit, wrapped_reinit) -ModuleWatchdog.register_module_hook("gevent.hub", patch_gevent_hub_reinit) +if asbool(os.getenv("_DD_TRACE_GEVENT_HUB_PATCHED", default=False)): + ModuleWatchdog.register_module_hook("gevent.hub", patch_gevent_hub_reinit) def ddtrace_after_in_child(): diff --git a/tests/internal/test_forksafe.py b/tests/internal/test_forksafe.py index 367af80d3b2..a0bed0ca1d4 100644 --- a/tests/internal/test_forksafe.py +++ b/tests/internal/test_forksafe.py @@ -291,6 +291,7 @@ def fn(): @pytest.mark.subprocess( out="" if (3,) < sys.version_info < (3, 7) else ("CTCTCT" if sys.platform == "darwin" else "CCCTTT"), err=None, + env=dict(_DD_TRACE_GEVENT_HUB_PATCHED="true"), ) def test_gevent_reinit_patch(): import os