From 8b54df9072b49e0023f812bd7ddbe602c910108f Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Mon, 5 Oct 2015 16:12:27 +0300 Subject: [PATCH] Keep lock type when reseting internal locks When Event._reset_internal_locks was called after fork, it use to reinitialize its condition without arguments, using RLock instead of Lock. --- Lib/test/lock_tests.py | 7 +++++++ Lib/threading.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py index b325bce..719d02c 100644 --- a/Lib/test/lock_tests.py +++ b/Lib/test/lock_tests.py @@ -394,6 +394,13 @@ class EventTests(BaseTestCase): b.wait_for_finished() self.assertEqual(results, [True] * N) + def test_reset_internal_locks(self): + evt = self.eventtype() + oldlock = evt._cond._lock + evt._reset_internal_locks() + newlock = evt._cond._lock + self.assertNotEqual(newlock, oldlock) + self.assertEqual(type(newlock), type(oldlock)) class ConditionTests(BaseTestCase): """ diff --git a/Lib/threading.py b/Lib/threading.py index 24cc911..4b4ec38 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -499,7 +499,7 @@ class Event: def _reset_internal_locks(self): # private! called by Thread._reset_internal_locks by _after_fork() - self._cond.__init__() + self._cond.__init__(Lock()) def is_set(self): """Return true if and only if the internal flag is true.""" -- 2.4.3