summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2017-05-17 14:02:55 (GMT)
committerGitHub <noreply@github.com>2017-05-17 14:02:55 (GMT)
commit9081b36f330964faa4dee3af03228d2ca7c71835 (patch)
tree0c30230dc346a90c6ae215bfeaf1f12234a9e701
parentf01c0ec9fe571e8afd50d2f5180db3c0d7b613af (diff)
downloadcpython-9081b36f330964faa4dee3af03228d2ca7c71835.zip
cpython-9081b36f330964faa4dee3af03228d2ca7c71835.tar.gz
cpython-9081b36f330964faa4dee3af03228d2ca7c71835.tar.bz2
bpo-30301: Fix AttributeError when using SimpleQueue.empty() (#1601) (#1627)
Under *spawn* and *forkserver* start methods, SimpleQueue.empty() could raise AttributeError due to not setting _poll in __setstate__.
-rw-r--r--Lib/multiprocessing/queues.py1
-rw-r--r--Lib/test/_test_multiprocessing.py36
-rw-r--r--Misc/NEWS3
3 files changed, 40 insertions, 0 deletions
diff --git a/Lib/multiprocessing/queues.py b/Lib/multiprocessing/queues.py
index 786a303..40ae10a 100644
--- a/Lib/multiprocessing/queues.py
+++ b/Lib/multiprocessing/queues.py
@@ -337,6 +337,7 @@ class SimpleQueue(object):
def __setstate__(self, state):
(self._reader, self._writer, self._rlock, self._wlock) = state
+ self._poll = self._reader.poll
def get(self):
with self._rlock:
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index e41845b..0402128 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -3868,6 +3868,42 @@ class TestSemaphoreTracker(unittest.TestCase):
self.assertRegex(err, expected)
self.assertRegex(err, 'semaphore_tracker: %r: \[Errno' % name1)
+class TestSimpleQueue(unittest.TestCase):
+
+ @classmethod
+ def _test_empty(cls, queue, child_can_start, parent_can_continue):
+ child_can_start.wait()
+ # issue 30301, could fail under spawn and forkserver
+ try:
+ queue.put(queue.empty())
+ queue.put(queue.empty())
+ finally:
+ parent_can_continue.set()
+
+ def test_empty(self):
+ queue = multiprocessing.SimpleQueue()
+ child_can_start = multiprocessing.Event()
+ parent_can_continue = multiprocessing.Event()
+
+ proc = multiprocessing.Process(
+ target=self._test_empty,
+ args=(queue, child_can_start, parent_can_continue)
+ )
+ proc.daemon = True
+ proc.start()
+
+ self.assertTrue(queue.empty())
+
+ child_can_start.set()
+ parent_can_continue.wait()
+
+ self.assertFalse(queue.empty())
+ self.assertEqual(queue.get(), True)
+ self.assertEqual(queue.get(), False)
+ self.assertTrue(queue.empty())
+
+ proc.join()
+
#
# Mixins
#
diff --git a/Misc/NEWS b/Misc/NEWS
index 9386cb4..a7a8d79 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -49,6 +49,9 @@ Extension Modules
Library
-------
+- bpo-30301: Fix AttributeError when using SimpleQueue.empty() under
+ *spawn* and *forkserver* start methods.
+
- bpo-30329: imaplib and poplib now catch the Windows socket WSAEINVAL error
(code 10022) on shutdown(SHUT_RDWR): An invalid operation was attempted.
This error occurs sometimes on SSL connections.