[Python-checkins] cpython (merge 3.4 -> default): Merge: #11866: Eliminate race condition in the computation of names for new
r.david.murray
python-checkins at python.org
Sat Oct 4 23:47:06 CEST 2014
https://hg.python.org/cpython/rev/e9afcce9a154
changeset: 92814:e9afcce9a154
parent: 92811:d748a3503ad5
parent: 92813:a6906b9e21d5
user: R David Murray <rdmurray at bitdance.com>
date: Sat Oct 04 17:45:15 2014 -0400
summary:
Merge: #11866: Eliminate race condition in the computation of names for new threads.
files:
Lib/threading.py | 9 ++++-----
Misc/NEWS | 3 +++
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/Lib/threading.py b/Lib/threading.py
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -6,7 +6,7 @@
from time import monotonic as _time
from traceback import format_exc as _format_exc
from _weakrefset import WeakSet
-from itertools import islice as _islice
+from itertools import islice as _islice, count as _count
try:
from _collections import deque as _deque
except ImportError:
@@ -729,11 +729,10 @@
# Helper to generate new thread names
-_counter = 0
+_counter = _count().__next__
+_counter() # Consume 0 so first non-main thread has id 1.
def _newname(template="Thread-%d"):
- global _counter
- _counter += 1
- return template % _counter
+ return template % _counter()
# Active thread administration
_active_limbo_lock = _allocate_lock()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -162,6 +162,9 @@
Library
-------
+- Issue #11866: Eliminated race condition in the computation of names
+ for new threads.
+
- Issue #21905: Avoid RuntimeError in pickle.whichmodule() when sys.modules
is mutated while iterating. Patch by Olivier Grisel.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list