Author: tack
Date: Sat Feb 2 16:33:50 2008
New Revision: 3015
Log:
New InProgress.wait() method; update Socket.connect() to use InProgress.wait()
Modified:
trunk/base/src/notifier/async.py
trunk/base/src/notifier/sockets.py
Modified: trunk/base/src/notifier/async.py
==============================================================================
--- trunk/base/src/notifier/async.py (original)
+++ trunk/base/src/notifier/async.py Sat Feb 2 16:33:50 2008
@@ -199,6 +199,32 @@
return self._result
+ def wait(self):
+ """
+ Waits for the result (or exception) of the InProgress object. The
+ main loop is kept alive.
+ """
+ # Import modules here rather than globally to avoid circular importing.
+ import main
+ if not main.is_running():
+ # No main loop is running yet. We're calling step() below,
+ # but we won't get notified of any thread completion
+ # unless the thread notifier pipe is initialized.
+ from thread import set_as_mainthread
+ set_as_mainthread()
+
+ if self.exception.count() == 0:
+ # No existing exception handler. Connect a dummy handler to
+ # prevent it from being logged in throw(). It will get raised
+ # later when we call get_result().
+ in_progress.exception.connect(lambda *args: None)
+
+ while not self.is_finished():
+ main.step()
+
+ return self.get_result()
+
+
def _connect(self, callback, args = (), kwargs = {}, once = False,
weak = False, pos = -1):
"""
Modified: trunk/base/src/notifier/sockets.py
==============================================================================
--- trunk/base/src/notifier/sockets.py (original)
+++ trunk/base/src/notifier/sockets.py Sat Feb 2 16:33:50 2008
@@ -37,10 +37,9 @@
import logging
import nf_wrapper as notifier
-import main
from jobserver import execute_in_thread
from callback import Callback, Signal
-from thread import MainThreadCallback, ThreadCallback, is_mainthread,
set_as_mainthread
+from thread import MainThreadCallback, ThreadCallback, is_mainthread
# get logging object
log = logging.getLogger('notifier')
@@ -165,11 +164,12 @@
established. Otherwise a Unix socket is established and addr is
treated as a filename.
- If async is not None, it is a callback that will be invoked when the
- connection has been established. This callback takes one or three
- parameters: if the connection was successful, the first parameter is
- True; otherwise there was an exception, and the three parameters are
- type, value, and traceback of the exception.
+ If async is not None, then an InProgress object is returned. If async
+ is a callable, then it is automatically connected to both completed and
+ exception handlers of the InProgress object. This callback takes one
+ or three parameters: if the connection was successful, the first
+ parameter is True; otherwise there was an exception, and the three
+ parameters are type, value, and traceback of the exception.
If async is None, this call will block until either connected or an
exception is raised. Although this call blocks, the notifier loop
@@ -177,29 +177,15 @@
"""
self._make_socket(addr)
- if async is not None and not callable(async):
- raise ValueError, 'async argument must be callable'
-
in_progress = self._connect_thread()
if async:
- in_progress.connect_both(async, async)
- return
- elif not main.is_running():
- # No main loop is running yet. We're calling step() below,
- # but we won't get notified of the connect thread completion
- # unless the thread notifier pipe is initialized.
- set_as_mainthread()
-
- # Connect a dummy handler to exception to prevent it from being
- # logged. We will reraise it after.
- in_progress.exception.connect(lambda *args: None)
-
- while not in_progress.is_finished():
- main.step()
+ if callable(async):
+ in_progress.connect_both(async, async)
+ return in_progress
# Any exception that occurred in the thread will get raised here:
- return in_progress.get_result()
+ return in_progress.wait()
@execute_in_thread()
-------------------------------------------------------------------------
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