summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing/managers.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2012-04-17 16:45:57 (GMT)
committerCharles-François Natali <neologix@free.fr>2012-04-17 16:45:57 (GMT)
commitc8ce715a82fd8034ef1d809b262346c15f2490c4 (patch)
tree125522b5a5daa37ba405f81902aeebe8d91b6c7f /Lib/multiprocessing/managers.py
parenta3f4457b172a165fafa65d67e0293f89dbba06b7 (diff)
downloadcpython-c8ce715a82fd8034ef1d809b262346c15f2490c4.zip
cpython-c8ce715a82fd8034ef1d809b262346c15f2490c4.tar.gz
cpython-c8ce715a82fd8034ef1d809b262346c15f2490c4.tar.bz2
Issue #14087: multiprocessing: add Condition.wait_for(). Patch by sbt.
Diffstat (limited to 'Lib/multiprocessing/managers.py')
-rw-r--r--Lib/multiprocessing/managers.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py
index eaf912c..d1c9d45 100644
--- a/Lib/multiprocessing/managers.py
+++ b/Lib/multiprocessing/managers.py
@@ -48,6 +48,7 @@ from traceback import format_exc
from multiprocessing import Process, current_process, active_children, Pool, util, connection
from multiprocessing.process import AuthenticationString
from multiprocessing.forking import exit, Popen, ForkingPickler
+from time import time as _time
#
# Register some things for pickling
@@ -996,6 +997,24 @@ class ConditionProxy(AcquirerProxy):
return self._callmethod('notify')
def notify_all(self):
return self._callmethod('notify_all')
+ def wait_for(self, predicate, timeout=None):
+ result = predicate()
+ if result:
+ return result
+ if timeout is not None:
+ endtime = _time() + timeout
+ else:
+ endtime = None
+ waittime = None
+ while not result:
+ if endtime is not None:
+ waittime = endtime - _time()
+ if waittime <= 0:
+ break
+ self.wait(waittime)
+ result = predicate()
+ return result
+
class EventProxy(BaseProxy):
_exposed_ = ('is_set', 'set', 'clear', 'wait')