changeset: 92813:a6906b9e21d5 branch: 3.4 parent: 92809:86ba3bdfac15 user: R David Murray date: Sat Oct 04 17:43:54 2014 -0400 files: Lib/threading.py Misc/NEWS description: #11866: Eliminate race condition in the computation of names for new threads. Original patch by Peter Saveliev. diff -r 86ba3bdfac15 -r a6906b9e21d5 Lib/threading.py --- a/Lib/threading.py Sat Oct 04 22:15:27 2014 +0200 +++ b/Lib/threading.py Sat Oct 04 17:43:54 2014 -0400 @@ -9,7 +9,7 @@ from time import time 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: @@ -726,11 +726,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 -r 86ba3bdfac15 -r a6906b9e21d5 Misc/NEWS --- a/Misc/NEWS Sat Oct 04 22:15:27 2014 +0200 +++ b/Misc/NEWS Sat Oct 04 17:43:54 2014 -0400 @@ -22,6 +22,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.