https://github.com/python/cpython/commit/c8729c9909e150989050ce2a435d018955bea41d
commit: c8729c9909e150989050ce2a435d018955bea41d
branch: main
author: Shamil <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2025-10-18T16:31:53+05:30
summary:
gh-140257: fix data race on eval_breaker during finalization (#140265)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-20-23-19.gh-issue-140257.8Txmem.rst
M Python/pystate.c
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-20-23-19.gh-issue-140257.8Txmem.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-20-23-19.gh-issue-140257.8Txmem.rst
new file mode 100644
index 00000000000000..50f7e0e48ae369
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2025-10-17-20-23-19.gh-issue-140257.8Txmem.rst
@@ -0,0 +1,2 @@
+Fix data race between interpreter_clear() and take_gil() on eval_breaker
+during finalization with daemon threads.
diff --git a/Python/pystate.c b/Python/pystate.c
index dbed609f29aa07..c402d89a16145b 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -763,10 +763,11 @@ interpreter_clear(PyInterpreterState *interp,
PyThreadState *tstate)
Py_CLEAR(interp->audit_hooks);
- // At this time, all the threads should be cleared so we don't need atomic
- // operations for instrumentation_version or eval_breaker.
+ // gh-140257: Threads have already been cleared, but daemon threads may
+ // still access eval_breaker atomically via take_gil() right before they
+ // hang. Use an atomic store to prevent data races during finalization.
interp->ceval.instrumentation_version = 0;
- tstate->eval_breaker = 0;
+ _Py_atomic_store_uintptr(&tstate->eval_breaker, 0);
for (int i = 0; i < _PY_MONITORING_UNGROUPED_EVENTS; i++) {
interp->monitors.tools[i] = 0;
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]