Author: dmeyer
Date: Wed Mar 19 11:45:19 2008
New Revision: 3201
Log:
add timeout support for InProgress
Modified:
trunk/base/src/notifier/async.py
trunk/base/src/notifier/coroutine.py
Modified: trunk/base/src/notifier/async.py
==============================================================================
--- trunk/base/src/notifier/async.py (original)
+++ trunk/base/src/notifier/async.py Wed Mar 19 11:45:19 2008
@@ -195,12 +195,6 @@
return not self._finished
- def finished(self, result):
- # XXX: Temporary wrapper for deprecated method name.
- log.warning('InProgress.finished() deprecated; use
InProgress.finish()')
- return self.finish(result)
-
-
def finish(self, result):
"""
This function should be called when the creating function is
@@ -362,6 +356,28 @@
return self._result
+ def timeout(self, timeout, callback=None):
+ """
+ Return an InProgress object linked to this one that will throw
+ a TimeoutException if this object is not finished in time. This
+ will not affect this InProgress object. If callback is given, the
+ callback will be called just before TimeoutException is raised.
+ """
+ # Import modules here rather than globally to avoid circular importing.
+ from timer import OneShotTimer
+ async = InProgress()
+ def trigger():
+ self.disconnect(async.finish)
+ self.exception.disconnect(async.throw)
+ if not async._finished:
+ if callback:
+ callback()
+ async.throw(TimeoutException, TimeoutException('timeout'),
None)
+ async.link(self)
+ OneShotTimer(trigger).start(timeout)
+ return async
+
+
def wait(self, timeout = None):
"""
Waits for the result (or exception) of the InProgress object. The
Modified: trunk/base/src/notifier/coroutine.py
==============================================================================
--- trunk/base/src/notifier/coroutine.py (original)
+++ trunk/base/src/notifier/coroutine.py Wed Mar 19 11:45:19 2008
@@ -235,6 +235,10 @@
"""
if self._timer and self._timer.active():
self._timer.stop()
+ # if this object waits for another CoroutineInProgress, stop
+ # that one, too.
+ if isinstance(self._async, CoroutineInProgress):
+ self._async.stop()
# Remove the internal timer, the async result and the
# generator function to remove bad circular references.
self._timer = None
@@ -242,6 +246,15 @@
self._async = None
+ def timeout(self, timeout):
+ """
+ Return an InProgress object linked to this one that will throw
+ a TimeoutException if this object is not finished in time. If used,
+ this will stop the coroutine.
+ """
+ return InProgress.timeout(self, timeout, callback=self.stop)
+
+
class CoroutineInProgressLock(CoroutineInProgress):
"""
CoroutineInProgress for handling locked coroutine functions.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog