changeset: 88339:9223dfa2ae5b tag: tip parent: 88336:247f12fecf2b user: Torsten Landschoff date: Mon Jan 06 16:28:03 2014 +0100 summary: multiprocessing.Queue(timeout=x) always polls the Queue if x >= 0. diff -r 247f12fecf2b -r 9223dfa2ae5b Lib/multiprocessing/queues.py --- a/Lib/multiprocessing/queues.py Sun Jan 05 12:00:31 2014 -0800 +++ b/Lib/multiprocessing/queues.py Mon Jan 06 16:28:03 2014 +0100 @@ -102,8 +102,14 @@ raise Empty try: if block: + # Make sure that we poll for data at least once whatever + # the timeout. timeout = deadline - time.time() - if timeout < 0 or not self._poll(timeout): + if timeout < 0: + empty = not self._poll() + else: + empty = not self._poll(timeout) + if empty: raise Empty elif not self._poll(): raise Empty diff -r 247f12fecf2b -r 9223dfa2ae5b Lib/test/_test_multiprocessing.py --- a/Lib/test/_test_multiprocessing.py Sun Jan 05 12:00:31 2014 -0800 +++ b/Lib/test/_test_multiprocessing.py Mon Jan 06 16:28:03 2014 +0100 @@ -725,6 +725,19 @@ delta = time.time() - start self.assertGreaterEqual(delta, 0.18) + def test_timeout_0(self): + # timeout=0 should be equivalent to block=False. As should a very small timeout. + q = multiprocessing.Queue() + q.put("hi") + q.put("there") + # We need to sleep here to give the queue feeder thread time to feed the queue. + # Unfortunately, there is nothing like "flush" to make sure that the data we + # just put actually arrived in the queue. + time.sleep(0.1) + # Once the data is on the receiver side, q.get should retrieve it whatever the + # timeout. + assert q.get(timeout=0) == "hi" + assert q.get(timeout=1e-6) == "there" # # #