]> granicus.if.org Git - python/commitdiff
Fix multiprocessing.event to match the new threading.Event API
authorJesse Noller <jnoller@gmail.com>
Wed, 1 Apr 2009 03:45:50 +0000 (03:45 +0000)
committerJesse Noller <jnoller@gmail.com>
Wed, 1 Apr 2009 03:45:50 +0000 (03:45 +0000)
Doc/library/multiprocessing.rst
Lib/multiprocessing/synchronize.py
Lib/test/test_multiprocessing.py

index 3d66d14742056aa36a05b380772e63af8e43ad78..02f6ac1c4712a368485442bafb3ceccc481537f7 100644 (file)
@@ -836,6 +836,12 @@ object -- see :ref:`multiprocessing-managers`.
 .. class:: Event()
 
    A clone of :class:`threading.Event`.
+   This method returns the state of the internal semaphore on exit, so it
+   will always return ``True`` except if a timeout is given and the operation
+   times out.
+
+   .. versionchanged:: 2.7
+      Previously, the method always returned ``None``.
 
 .. class:: Lock()
 
index dacf45acca71dc0a3cac8c97881ff5dda6c0b5e1..716f3c700336a0ce5a6be74e682d2a0b0e71d379 100644 (file)
@@ -301,5 +301,10 @@ class Event(object):
                 self._flag.release()
             else:
                 self._cond.wait(timeout)
+
+            if self._flag.acquire(False):
+                self._flag.release()
+                return True
+            return False
         finally:
             self._cond.release()
index a446ac304d99fc29cf1d458d638d4d346e692b89..8ef2e2fc7b99dba8c5c2fba7a42d55aa36509b82 100644 (file)
@@ -749,20 +749,22 @@ class _TestEvent(BaseTestCase):
 
         # Removed temporaily, due to API shear, this does not
         # work with threading._Event objects. is_set == isSet
-        #self.assertEqual(event.is_set(), False)
+        self.assertEqual(event.is_set(), False)
 
-        self.assertEqual(wait(0.0), None)
+        # Removed, threading.Event.wait() will return the value of the __flag
+        # instead of None. API Shear with the semaphore backed mp.Event
+        self.assertEqual(wait(0.0), False)
         self.assertTimingAlmostEqual(wait.elapsed, 0.0)
-        self.assertEqual(wait(TIMEOUT1), None)
+        self.assertEqual(wait(TIMEOUT1), False)
         self.assertTimingAlmostEqual(wait.elapsed, TIMEOUT1)
 
         event.set()
 
         # See note above on the API differences
-        self.assertEqual(event.is_set(), True)
-        self.assertEqual(wait(), None)
+        self.assertEqual(event.is_set(), True)
+        self.assertEqual(wait(), True)
         self.assertTimingAlmostEqual(wait.elapsed, 0.0)
-        self.assertEqual(wait(TIMEOUT1), None)
+        self.assertEqual(wait(TIMEOUT1), True)
         self.assertTimingAlmostEqual(wait.elapsed, 0.0)
         # self.assertEqual(event.is_set(), True)
 
@@ -771,7 +773,7 @@ class _TestEvent(BaseTestCase):
         #self.assertEqual(event.is_set(), False)
 
         self.Process(target=self._test_event, args=(event,)).start()
-        self.assertEqual(wait(), None)
+        self.assertEqual(wait(), True)
 
 #
 #