summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_multiprocessing.py
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2012-05-10 15:11:12 (GMT)
committerRichard Oudkerk <shibturn@gmail.com>2012-05-10 15:11:12 (GMT)
commit59d5404bc79beaa39c76fb26012238b26e9b0166 (patch)
tree071cc74196e6fcc572c836b6be02a8d9a6bfc276 /Lib/test/test_multiprocessing.py
parentca5f91b888bc0056fc08d062f65cc783bbba8532 (diff)
downloadcpython-59d5404bc79beaa39c76fb26012238b26e9b0166.zip
cpython-59d5404bc79beaa39c76fb26012238b26e9b0166.tar.gz
cpython-59d5404bc79beaa39c76fb26012238b26e9b0166.tar.bz2
Issue #14753: Make multiprocessing treat negative timeouts as it did in 3.2
In Python 3.2 and earlier, Process.join() and Connection.poll() treated negative timeouts as zero timeouts. Earlier versions from the 3.3 line of development treat them as infinite timeouts. The patch reverts to the old behaviour.
Diffstat (limited to 'Lib/test/test_multiprocessing.py')
-rw-r--r--Lib/test/test_multiprocessing.py44
1 files changed, 28 insertions, 16 deletions
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
index a839917..d10d51b 100644
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -83,23 +83,13 @@ HAVE_GETVALUE = not getattr(_multiprocessing,
'HAVE_BROKEN_SEM_GETVALUE', False)
WIN32 = (sys.platform == "win32")
-if WIN32:
- from _winapi import WaitForSingleObject, INFINITE, WAIT_OBJECT_0
- def wait_for_handle(handle, timeout):
- if timeout is None or timeout < 0.0:
- timeout = INFINITE
- else:
- timeout = int(1000 * timeout)
- return WaitForSingleObject(handle, timeout) == WAIT_OBJECT_0
-else:
- from select import select
- _select = util._eintr_retry(select)
+from multiprocessing.connection import wait
- def wait_for_handle(handle, timeout):
- if timeout is not None and timeout < 0.0:
- timeout = None
- return handle in _select([handle], [], [], timeout)[0]
+def wait_for_handle(handle, timeout):
+ if timeout is not None and timeout < 0.0:
+ timeout = None
+ return wait([handle], timeout)
try:
MAXFD = os.sysconf("SC_OPEN_MAX")
@@ -291,9 +281,18 @@ class _TestProcess(BaseTestCase):
self.assertIn(p, self.active_children())
self.assertEqual(p.exitcode, None)
+ join = TimingWrapper(p.join)
+
+ self.assertEqual(join(0), None)
+ self.assertTimingAlmostEqual(join.elapsed, 0.0)
+ self.assertEqual(p.is_alive(), True)
+
+ self.assertEqual(join(-1), None)
+ self.assertTimingAlmostEqual(join.elapsed, 0.0)
+ self.assertEqual(p.is_alive(), True)
+
p.terminate()
- join = TimingWrapper(p.join)
self.assertEqual(join(), None)
self.assertTimingAlmostEqual(join.elapsed, 0.0)
@@ -1664,6 +1663,9 @@ class _TestConnection(BaseTestCase):
self.assertEqual(poll(), False)
self.assertTimingAlmostEqual(poll.elapsed, 0)
+ self.assertEqual(poll(-1), False)
+ self.assertTimingAlmostEqual(poll.elapsed, 0)
+
self.assertEqual(poll(TIMEOUT1), False)
self.assertTimingAlmostEqual(poll.elapsed, TIMEOUT1)
@@ -2785,6 +2787,16 @@ class TestWait(unittest.TestCase):
p.terminate()
p.join()
+ def test_neg_timeout(self):
+ from multiprocessing.connection import wait
+ a, b = multiprocessing.Pipe()
+ t = time.time()
+ res = wait([a], timeout=-1)
+ t = time.time() - t
+ self.assertEqual(res, [])
+ self.assertLess(t, 1)
+ a.close()
+ b.close()
#
# Issue 14151: Test invalid family on invalid environment