Provide meaningful names for coroutines, and report switches in the
debug output.
def cr(func, *args, **kw):
"""Return a function which invokes FUNC(*ARGS, **KW) in a coroutine."""
def cr(func, *args, **kw):
"""Return a function which invokes FUNC(*ARGS, **KW) in a coroutine."""
- def _(*hunoz, **hukairz):
- T.Coroutine(xwrap(func)).switch(*args, **kw)
- return _
+ name = T.funargstr(func, args, kw)
+ return lambda *hunoz, **hukairz: \
+ T.Coroutine(xwrap(func), name = name).switch(*args, **kw)
def incr(func):
"""Decorator: runs its function in a coroutine of its own."""
def incr(func):
"""Decorator: runs its function in a coroutine of its own."""
- return lambda *args, **kw: T.Coroutine(func).switch(*args, **kw)
+ return lambda *args, **kw: \
+ (T.Coroutine(func, name = T.funargstr(func, args, kw))
+ .switch(*args, **kw))
###--------------------------------------------------------------------------
### Random bits of infrastructure.
###--------------------------------------------------------------------------
### Random bits of infrastructure.
def tryupdate(me):
"""Start the updater coroutine, if it's not going already."""
if me.cr is None:
def tryupdate(me):
"""Start the updater coroutine, if it's not going already."""
if me.cr is None:
- me.cr = T.Coroutine(me._update)
+ me.cr = T.Coroutine(me._update,
+ name = 'update-peer-window %s' % me.peer.name)
me.cr.switch()
def stopupdate(me, *hunoz, **hukairz):
me.cr.switch()
def stopupdate(me, *hunoz, **hukairz):
"""
if me._kidding:
return
"""
if me._kidding:
return
- T.Coroutine(me._addautopeer_hack).switch(peer)
+ T.Coroutine(me._addautopeer_hack,
+ name = '_addautopeerhack %s' % peer).switch(peer)
def _addautopeer_hack(me, peer):
"""Make an automated connection to PEER in response to a user click."""
def _addautopeer_hack(me, peer):
"""Make an automated connection to PEER in response to a user click."""
"""
def switch(me, *args, **kw):
assert _Coroutine.getcurrent() is rootcr
"""
def switch(me, *args, **kw):
assert _Coroutine.getcurrent() is rootcr
+ if _debug: print '* %s' % me
_Coroutine.switch(me, *args, **kw)
_Coroutine.switch(me, *args, **kw)
+ if _debug: print '* %s' % rootcr
###--------------------------------------------------------------------------
### Default places for things.
###--------------------------------------------------------------------------
### Default places for things.
"""Call FUNC(*ARGS, **KW) later, in the root coroutine."""
_deferq.append((func, args, kw))
"""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."""
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()
## Asides.
_asideq = Queue()
global _deferq
assert _Coroutine.getcurrent() is rootcr
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
while not quitp():
while _deferq:
q = _deferq
Add the D-Bus monitor here, because we might send commands off immediately,
and we want to make sure the server connection is up.
"""
Add the D-Bus monitor here, because we might send commands off immediately,
and we want to make sure the server connection is up.
"""
- T.Coroutine(kickpeers).switch()
+ T.Coroutine(kickpeers, name = 'kickpeers').switch()
dbm = DBusMonitor()
dbm.addmon(NetworkManagerMonitor())
dbm.addmon(MaemoICdMonitor())
dbm = DBusMonitor()
dbm.addmon(NetworkManagerMonitor())
dbm.addmon(MaemoICdMonitor())
except KeyError:
return
if 'ifup' in info:
except KeyError:
return
if 'ifup' in info:
- T.Coroutine(ifupdown).switch('ifup', peer, info, ifname, *addr)
+ T.Coroutine(ifupdown, name = 'ifup %s' % peer) \
+ .switch('ifup', peer, info, ifname, *addr)
- T.Coroutine(connect).switch(peer, info['connect'])
+ T.Coroutine(connect, name = 'connect %s' % peer) \
+ .switch(peer, info['connect'])
if boolean(info, 'watch', False):
pinger.add(peer, info, False)
if boolean(info, 'watch', False):
pinger.add(peer, info, False)
except KeyError:
pass
if 'ifdown' in info:
except KeyError:
pass
if 'ifdown' in info:
- T.Coroutine(ifupdown).switch('ifdown', peer, info)
+ T.Coroutine(ifupdown, name = 'ifdown %s' % peer) \
+ .switch('ifdown', peer, info)
def notify(_, code, *rest):
"""
def notify(_, code, *rest):
"""
errorwatch = ErrorWatch()
childwatch = ChildWatch()
pinger = Pinger()
errorwatch = ErrorWatch()
childwatch = ChildWatch()
pinger = Pinger()
- T.Coroutine(dbwatch).switch()
+ T.Coroutine(dbwatch, name = 'dbwatch').switch()
errorwatch.switch()
pinger.switch()
errorwatch.switch()
pinger.switch()