Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ddtrace/bootstrap/cloning.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def drop(module_name: str) -> None:
"attr",
"google",
"google.protobuf", # the upb backend in >= 4.21 does not like being unloaded
"numpy", # its C extension cannot be re-initialized in >= 2.4 (numpy/numpy#29030)
"wrapt",
"bytecode", # needed by before-fork hooks
"pathlib", # used in singledispatch
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
tracing: This fix resolves an ``ImportError: cannot load module more than once per process``
that could occur when ``numpy`` (2.4 or later) was imported both before and after
``ddtrace.auto``.
21 changes: 21 additions & 0 deletions tests/internal/test_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ class B(A):
assert b


@pytest.mark.subprocess(env=dict(DD_UNLOAD_MODULES_FROM_SITECUSTOMIZE="true"))
def test_numpy_not_unloaded():
import sys

import ddtrace # noqa: F401

# numpy >= 2.4 refuses to re-initialize its C extension, so if cleanup drops
# it and user code re-imports, the second import raises ImportError. Keep it
# loaded across the cleanup. Regression test for issue #18276.
have_numpy = True
try:
import numpy # noqa: F401
except ImportError:
have_numpy = False

import ddtrace.auto # noqa: F401

if have_numpy:
assert "numpy" in sys.modules


@pytest.mark.subprocess(env=dict(DD_UNLOAD_MODULES_FROM_SITECUSTOMIZE="true"))
def test_yaml_not_unloaded():
# Regression test for APMS-20000. The module cleanup used to drop and force a
Expand Down