"""
def switch(me, *args, **kw):
assert _Coroutine.getcurrent() is rootcr
+ if _debug: print '* %s' % me
_Coroutine.switch(me, *args, **kw)
+ if _debug: print '* %s' % rootcr
###--------------------------------------------------------------------------
### Default places for things.
"""Call FUNC(*ARGS, **KW) later, in the root coroutine."""
_deferq.append((func, args, kw))
+def funargstr(func, args, kw):
+ items = [repr(a) for a in args]
+ for k, v in kw.iteritems():
+ items.append('%s = %r' % (k, v))
+ return '%s(%s)' % (func.__name__, ', '.join(items))
+
def spawn(func, *args, **kw):
"""Call FUNC, passing ARGS and KW, in a fresh coroutine."""
- defer(lambda: Coroutine(func).switch(*args, **kw))
+ defer(lambda: (Coroutine(func, name = funargstr(func, args, kw))
+ .switch(*args, **kw)))
## Asides.
_asideq = Queue()
global _deferq
assert _Coroutine.getcurrent() is rootcr
- Coroutine(_runasides).switch()
+ Coroutine(_runasides, name = '_runasides').switch()
+ if quitp is None:
+ quitp = me.quitp
while not quitp():
while _deferq:
q = _deferq