https://github.com/python/cpython/commit/5200f1192428becab0c31db98e7baa97f3c3c3e2
commit: 5200f1192428becab0c31db98e7baa97f3c3c3e2
branch: main
author: John <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2026-07-18T09:01:51-04:00
summary:
gh-153908: Fix data race in `itertools.count.__repr__` (GH-153917)
files:
A Misc/NEWS.d/next/Library/2026-07-18-11-16-41.gh-issue-153908.82FiGk.rst
M Modules/itertoolsmodule.c
diff --git
a/Misc/NEWS.d/next/Library/2026-07-18-11-16-41.gh-issue-153908.82FiGk.rst
b/Misc/NEWS.d/next/Library/2026-07-18-11-16-41.gh-issue-153908.82FiGk.rst
new file mode 100644
index 00000000000000..6ee943a5fb6672
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-07-18-11-16-41.gh-issue-153908.82FiGk.rst
@@ -0,0 +1 @@
+Fix data race when calling :func:`repr` on :class:`itertools.count` under the
:term:`free-threaded build`.
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 72bfab1abaf9ca..c0023c839ca7fe 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -3675,9 +3675,11 @@ static PyObject *
count_repr(PyObject *op)
{
countobject *lz = countobject_CAST(op);
- if (lz->long_cnt == NULL)
+ if (lz->long_cnt == NULL) {
+ Py_ssize_t cnt = FT_ATOMIC_LOAD_SSIZE_RELAXED(lz->cnt);
return PyUnicode_FromFormat("%s(%zd)",
- _PyType_Name(Py_TYPE(lz)), lz->cnt);
+ _PyType_Name(Py_TYPE(lz)), cnt);
+ }
if (PyLong_Check(lz->long_step)) {
long step = PyLong_AsLong(lz->long_step);
_______________________________________________
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]