Skip to content

Commit b8e4221

Browse files
committed
fix fork errors in py3.12
1 parent 98c3dd3 commit b8e4221

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

ddtrace/internal/telemetry/writer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,9 @@ def _fork_writer(self):
607607
if self.status == ServiceStatus.STOPPED:
608608
return
609609

610-
# # Enable writer service in child process to avoid interpreter shutdown
611-
# # error in Python 3.12
612-
# if sys.version_info >= (3, 12):
613-
# self.enable()
610+
# Enable writer service in child process to avoid interpreter shutdown
611+
# error in Python 3.12
612+
self.enable()
614613

615614
def _restart_sequence(self):
616615
self._sequence = itertools.count(1)

tests/telemetry/test_telemetry.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ def test_telemetry_enabled_on_first_tracer_flush(test_agent_session, ddtrace_run
4747
def test_enable_fork(test_agent_session, run_python_code_in_subprocess):
4848
"""assert app-started/app-closing events are only sent in parent process"""
4949
code = """
50+
import warnings
51+
# This test logs the following warning in py3.12:
52+
# This process (pid=402) is multi-threaded, use of fork() may lead to deadlocks in the child
53+
warnings.filterwarnings("ignore", category=DeprecationWarning)
54+
5055
import os
5156
5257
from ddtrace.internal.runtime import get_runtime_id
@@ -68,7 +73,7 @@ def test_enable_fork(test_agent_session, run_python_code_in_subprocess):
6873

6974
stdout, stderr, status, _ = run_python_code_in_subprocess(code)
7075
assert status == 0, stderr
71-
assert stderr == b""
76+
assert stderr == b"", stderr
7277

7378
runtime_id = stdout.strip().decode("utf-8")
7479

@@ -86,6 +91,11 @@ def test_enable_fork(test_agent_session, run_python_code_in_subprocess):
8691
def test_enable_fork_heartbeat(test_agent_session, run_python_code_in_subprocess):
8792
"""assert app-heartbeat events are only sent in parent process when no other events are queued"""
8893
code = """
94+
import warnings
95+
# This test logs the following warning in py3.12:
96+
# This process (pid=402) is multi-threaded, use of fork() may lead to deadlocks in the child
97+
warnings.filterwarnings("ignore", category=DeprecationWarning)
98+
8999
import os
90100
91101
from ddtrace.internal.runtime import get_runtime_id
@@ -107,7 +117,7 @@ def test_enable_fork_heartbeat(test_agent_session, run_python_code_in_subprocess
107117

108118
stdout, stderr, status, _ = run_python_code_in_subprocess(code)
109119
assert status == 0, stderr
110-
assert stderr == b""
120+
assert stderr == b"", stderr
111121

112122
runtime_id = stdout.strip().decode("utf-8")
113123

@@ -125,6 +135,11 @@ def test_heartbeat_interval_configuration(run_python_code_in_subprocess):
125135
env = os.environ.copy()
126136
env["DD_TELEMETRY_HEARTBEAT_INTERVAL"] = "61"
127137
code = """
138+
import warnings
139+
# This test logs the following warning in py3.12:
140+
# This process (pid=402) is multi-threaded, use of fork() may lead to deadlocks in the child
141+
warnings.filterwarnings("ignore", category=DeprecationWarning)
142+
128143
from ddtrace import config
129144
assert config._telemetry_heartbeat_interval == 61
130145
@@ -143,6 +158,11 @@ def test_logs_after_fork(run_python_code_in_subprocess):
143158
# Regression test: telemetry writer should not log an error when a process forks
144159
_, err, status, _ = run_python_code_in_subprocess(
145160
"""
161+
import warnings
162+
# This test logs the following warning in py3.12:
163+
# This process (pid=402) is multi-threaded, use of fork() may lead to deadlocks in the child
164+
warnings.filterwarnings("ignore", category=DeprecationWarning)
165+
146166
import ddtrace
147167
import logging
148168
import os
@@ -154,7 +174,7 @@ def test_logs_after_fork(run_python_code_in_subprocess):
154174
)
155175

156176
assert status == 0, err
157-
assert err == b""
177+
assert err == b"", err
158178

159179

160180
def test_app_started_error_handled_exception(test_agent_session, run_python_code_in_subprocess):

0 commit comments

Comments
 (0)