[Python-checkins] cpython (2.7): reinitialize an Event's Condition with a regular lock (closes #25319)

benjamin.peterson python-checkins at python.org
Tue Oct 6 01:01:38 EDT 2015


https://hg.python.org/cpython/rev/69a26f0800b3
changeset:   98548:69a26f0800b3
branch:      2.7
parent:      98536:45a04eadefd6
user:        Benjamin Peterson <benjamin at python.org>
date:        Mon Oct 05 21:56:22 2015 -0700
summary:
  reinitialize an Event's Condition with a regular lock (closes #25319)

files:
  Lib/test/lock_tests.py |  8 ++++++++
  Lib/threading.py       |  2 +-
  Misc/ACKS              |  1 +
  Misc/NEWS              |  3 +++
  4 files changed, 13 insertions(+), 1 deletions(-)


diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -305,6 +305,14 @@
         for r, dt in results2:
             self.assertTrue(r)
 
+    def test_reset_internal_locks(self):
+        evt = self.eventtype()
+        old_lock = evt._Event__cond._Condition__lock
+        evt._reset_internal_locks()
+        new_lock = evt._Event__cond._Condition__lock
+        self.assertIsNot(new_lock, old_lock)
+        self.assertIs(type(new_lock), type(old_lock))
+
 
 class ConditionTests(BaseTestCase):
     """
diff --git a/Lib/threading.py b/Lib/threading.py
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -565,7 +565,7 @@
 
     def _reset_internal_locks(self):
         # private!  called by Thread._reset_internal_locks by _after_fork()
-        self.__cond.__init__()
+        self.__cond.__init__(Lock())
 
     def isSet(self):
         'Return true if and only if the internal flag is true.'
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1290,6 +1290,7 @@
 Rafal Smotrzyk
 Eric Snow
 Dirk Soede
+Nir Soffer
 Paul Sokolovsky
 Evgeny Sologubov
 Cody Somerville
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -43,6 +43,9 @@
 Library
 -------
 
+- Issue #25319: When threading.Event is reinitialized, the underlying condition
+  should use a regular lock rather than a recursive lock.
+
 - Issue #25232: Fix CGIRequestHandler to split the query from the URL at the
   first question mark (?) rather than the last. Patch from Xiang Zhang.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list