Author: tack
Date: Wed Feb 13 20:22:52 2008
New Revision: 3091

Log:
Don't wrap return value from non-generator coroutine wrapped functions after
all.  (I advocated this a while back, but doing this may conceal an
actual problem that the user should know about.)  So we raise an exception
instead.

Log a warning if a thread callback is a generator or returns an InProgress
object, because this likely means the threaded function is being treated
like a coroutine.  It'd be nice if this worked, but that's a TODO.


Modified:
   trunk/base/src/notifier/coroutine.py
   trunk/base/src/notifier/thread.py

Modified: trunk/base/src/notifier/coroutine.py
==============================================================================
--- trunk/base/src/notifier/coroutine.py        (original)
+++ trunk/base/src/notifier/coroutine.py        Wed Feb 13 20:22:52 2008
@@ -147,15 +147,17 @@
     InProgress object. It may already be finished.
     """
     def decorator(func):
-
         def newfunc(*args, **kwargs):
             result = func(*args, **kwargs)
             if not hasattr(result, 'next'):
                 # Decorated function doesn't have a next attribute, which
-                # likyle means it didn't yield anything.  There was no sense
-                # in decorating that function with coroutine, but on
-                # the other hand it's easy enough just to return the result.
-                return _wrap_result(result)
+                # means it isn't a generator.  We might simply wrap the result
+                # in an InProgress and pass it back, but for example if the
+                # coroutine is wrapping a @threaded decorated function which is
+                # itself a generator, wrapping the result will silently not 
work
+                # with any indication why.  It's better to raise an exception.
+                raise ValueError('@coroutine decorated function is not a 
generator')
+
             function = result
             if synchronize and func._lock is not None and not 
func._lock.is_finished():
                 # Function is currently called by someone else

Modified: trunk/base/src/notifier/thread.py
==============================================================================
--- trunk/base/src/notifier/thread.py   (original)
+++ trunk/base/src/notifier/thread.py   Wed Feb 13 20:22:52 2008
@@ -59,6 +59,7 @@
 import socket
 import errno
 import thread
+import types
 
 # notifier imports
 import nf_wrapper as notifier
@@ -273,9 +274,15 @@
         if self._callback is None:
             return None
         try:
-            MainThreadCallback(self.finished)(self._callback())
+            result = self._callback()
         except:
             MainThreadCallback(self.throw)(*sys.exc_info())
+        else:
+            if type(result) == types.GeneratorType or isinstance(result, 
InProgress):
+                # Looks like the callback is yielding something, or callback 
is a
+                # coroutine-decorated function.  Not supported (yet?).
+                log.warning('NYI: threads cannot yet be coroutines.')
+            MainThreadCallback(self.finished)(result)
         self._callback = None
 
 

-------------------------------------------------------------------------
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

Reply via email to