bpo-30301: Fix AttributeError when using SimpleQueue.empty() (#1601) … · python/cpython@43d4c03 (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -337,6 +337,7 @@ def __getstate__(self):
337 337
338 338 def __setstate__(self, state):
339 339 (self._reader, self._writer, self._rlock, self._wlock) = state
340 +self._poll = self._reader.poll
340 341
341 342 def get(self):
342 343 with self._rlock:
Original file line number Diff line number Diff line change
@@ -3958,6 +3958,42 @@ def test_semaphore_tracker(self):
3958 3958 self.assertRegex(err, expected)
3959 3959 self.assertRegex(err, r'semaphore_tracker: %r: \[Errno' % name1)
3960 3960
3961 +class TestSimpleQueue(unittest.TestCase):
3962 +
3963 +@classmethod
3964 +def _test_empty(cls, queue, child_can_start, parent_can_continue):
3965 +child_can_start.wait()
3966 +# issue 30301, could fail under spawn and forkserver
3967 +try:
3968 +queue.put(queue.empty())
3969 +queue.put(queue.empty())
3970 +finally:
3971 +parent_can_continue.set()
3972 +
3973 +def test_empty(self):
3974 +queue = multiprocessing.SimpleQueue()
3975 +child_can_start = multiprocessing.Event()
3976 +parent_can_continue = multiprocessing.Event()
3977 +
3978 +proc = multiprocessing.Process(
3979 +target=self._test_empty,
3980 +args=(queue, child_can_start, parent_can_continue)
3981 + )
3982 +proc.daemon = True
3983 +proc.start()
3984 +
3985 +self.assertTrue(queue.empty())
3986 +
3987 +child_can_start.set()
3988 +parent_can_continue.wait()
3989 +
3990 +self.assertFalse(queue.empty())
3991 +self.assertEqual(queue.get(), True)
3992 +self.assertEqual(queue.get(), False)
3993 +self.assertTrue(queue.empty())
3994 +
3995 +proc.join()
3996 +
3961 3997 #
3962 3998 # Mixins
3963 3999 #
Original file line number Diff line number Diff line change
@@ -36,6 +36,9 @@ Core and Builtins
36 36 Library
37 37 -------
38 38
39 +- bpo-30301: Fix AttributeError when using SimpleQueue.empty() under
40 + *spawn* and *forkserver* start methods.
41 +
39 42 - bpo-30329: imaplib and poplib now catch the Windows socket WSAEINVAL error
40 43 (code 10022) on shutdown(SHUT_RDWR): An invalid operation was attempted.
41 44 This error occurs sometimes on SSL connections.