From 72b1c627be3545bf7184894c0528c9774ffcc9b9 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 | 8 ++++++++ Lib/threading.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py index 2ff75c4..fa7f226 100644 --- a/Lib/test/lock_tests.py +++ b/Lib/test/lock_tests.py @@ -305,6 +305,14 @@ class EventTests(BaseTestCase): for r, dt in results2: self.assertTrue(r) + def test_reset_internal_locks(self): + evt = self.eventtype() + oldlock = evt._Event__cond._Condition__lock + evt._reset_internal_locks() + newlock = evt._Event__cond._Condition__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 27a5511..51205fa 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -565,7 +565,7 @@ class _Event(_Verbose): 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.' -- 2.4.3