From 74449a49cf0d67ccda60c5f26fc5e4936731ff7f Mon Sep 17 00:00:00 2001 From: Yun Kim Date: Wed, 15 Feb 2023 10:34:09 -0500 Subject: [PATCH 1/5] Unload time, don't unload typing --- ddtrace/bootstrap/sitecustomize.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ddtrace/bootstrap/sitecustomize.py b/ddtrace/bootstrap/sitecustomize.py index c2a8e8c572b..9244572a240 100644 --- a/ddtrace/bootstrap/sitecustomize.py +++ b/ddtrace/bootstrap/sitecustomize.py @@ -12,7 +12,12 @@ import os # noqa -MODULES_TO_NOT_CLEANUP = {"atexit", "asyncio", "attr", "concurrent", "ddtrace", "logging"} +""" +The following modules cause problems when being unloaded/reloaded in module cloning. +Notably, unloading the atexit module will remove all registered hooks which we use for cleaning up on tracer shutdown. +The other listed modules internally maintain some state that does not coexist well if reloaded. +""" +MODULES_TO_NOT_CLEANUP = {"atexit", "asyncio", "attr", "concurrent", "ddtrace", "logging", "typing"} if sys.version_info <= (2, 7): MODULES_TO_NOT_CLEANUP |= {"encodings", "codecs"} import imp @@ -72,6 +77,9 @@ def cleanup_loaded_modules(aggressive=False): break else: del sys.modules[module_name] + # Some versions of CPython import the time module during interpreter startup, which needs to be unloaded. + if "time" in sys.modules: + del sys.modules["time"] will_run_module_cloning = should_cleanup_loaded_modules() From 7da90b1a0b21aa7c44dd5f4272c93fd6830ad190 Mon Sep 17 00:00:00 2001 From: Yun Kim Date: Wed, 15 Feb 2023 11:09:16 -0500 Subject: [PATCH 2/5] Test gunicorn/gevent on all Python versions to see what works --- riotfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riotfile.py b/riotfile.py index acc113fad1e..ecf5c04dd74 100644 --- a/riotfile.py +++ b/riotfile.py @@ -2604,7 +2604,7 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION): pkgs={"requests": latest, "gevent": latest}, venvs=[ Venv( - pys=select_pys(min_version="3.8"), + pys=select_pys(), pkgs={"gunicorn": ["==19.10.0", "==20.0.4", latest]}, ), ], From 89f32882dfb387a8cd7e7a7a8924e52b9adb6230 Mon Sep 17 00:00:00 2001 From: Yun Kim Date: Wed, 15 Feb 2023 11:30:13 -0500 Subject: [PATCH 3/5] Split typing into separate branch, update riotfile (no 2.7) --- ddtrace/bootstrap/sitecustomize.py | 4 +++- riotfile.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ddtrace/bootstrap/sitecustomize.py b/ddtrace/bootstrap/sitecustomize.py index 9244572a240..28a07366f76 100644 --- a/ddtrace/bootstrap/sitecustomize.py +++ b/ddtrace/bootstrap/sitecustomize.py @@ -17,7 +17,9 @@ Notably, unloading the atexit module will remove all registered hooks which we use for cleaning up on tracer shutdown. The other listed modules internally maintain some state that does not coexist well if reloaded. """ -MODULES_TO_NOT_CLEANUP = {"atexit", "asyncio", "attr", "concurrent", "ddtrace", "logging", "typing"} +MODULES_TO_NOT_CLEANUP = {"atexit", "asyncio", "attr", "concurrent", "ddtrace", "logging"} +if sys.version_info <= (3, 7): + MODULES_TO_NOT_CLEANUP |= {"typing"} # required by older versions of Python if sys.version_info <= (2, 7): MODULES_TO_NOT_CLEANUP |= {"encodings", "codecs"} import imp diff --git a/riotfile.py b/riotfile.py index ecf5c04dd74..e0397dc6a47 100644 --- a/riotfile.py +++ b/riotfile.py @@ -2604,7 +2604,7 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION): pkgs={"requests": latest, "gevent": latest}, venvs=[ Venv( - pys=select_pys(), + pys=select_pys(min_version="3.5"), pkgs={"gunicorn": ["==19.10.0", "==20.0.4", latest]}, ), ], From 86eeb8bd9e86ab5155a4e2e5ed83d38c14f6cf73 Mon Sep 17 00:00:00 2001 From: Yun Kim Date: Wed, 15 Feb 2023 15:35:44 -0500 Subject: [PATCH 4/5] Reset gunicorn tests to run with Python >= 3.8 --- riotfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riotfile.py b/riotfile.py index e0397dc6a47..acc113fad1e 100644 --- a/riotfile.py +++ b/riotfile.py @@ -2604,7 +2604,7 @@ def select_pys(min_version=MIN_PYTHON_VERSION, max_version=MAX_PYTHON_VERSION): pkgs={"requests": latest, "gevent": latest}, venvs=[ Venv( - pys=select_pys(min_version="3.5"), + pys=select_pys(min_version="3.8"), pkgs={"gunicorn": ["==19.10.0", "==20.0.4", latest]}, ), ], From e5face76c8e1270708be30207ce39bc21acce616 Mon Sep 17 00:00:00 2001 From: Yun Kim Date: Thu, 16 Feb 2023 09:10:28 -0500 Subject: [PATCH 5/5] Fix incorrect version check for typing --- ddtrace/bootstrap/sitecustomize.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddtrace/bootstrap/sitecustomize.py b/ddtrace/bootstrap/sitecustomize.py index 28a07366f76..b482528824b 100644 --- a/ddtrace/bootstrap/sitecustomize.py +++ b/ddtrace/bootstrap/sitecustomize.py @@ -18,7 +18,7 @@ The other listed modules internally maintain some state that does not coexist well if reloaded. """ MODULES_TO_NOT_CLEANUP = {"atexit", "asyncio", "attr", "concurrent", "ddtrace", "logging"} -if sys.version_info <= (3, 7): +if sys.version_info < (3, 7): MODULES_TO_NOT_CLEANUP |= {"typing"} # required by older versions of Python if sys.version_info <= (2, 7): MODULES_TO_NOT_CLEANUP |= {"encodings", "codecs"}