chiark / gitweb /
debian/rules: Throw the contrib scripts into `examples'.
[tripe] / py / tripe.py.in
index 2e21885b8797ba7e18c3a4af009ffd0a41d3a36a..cefb667f0e291c6225a566e76648e16e01c2f3ae 100644 (file)
@@ -128,7 +128,9 @@ class Coroutine (_Coroutine):
   """
   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.
@@ -610,9 +612,16 @@ def defer(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."""
-  defer(lambda: Coroutine(func).switch(*args, **kw))
+  defer(lambda: (Coroutine(func, name = funargstr(func, args, kw))
+                 .switch(*args, **kw)))
 
 ## Asides.
 _asideq = Queue()
@@ -702,7 +711,9 @@ class TripeCommandDispatcher (TripeConnection):
 
     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
@@ -819,7 +830,8 @@ class TripeCommandDispatcher (TripeConnection):
   def add(me, peer, *addr, **kw):
     return _simple(me.command(bg = True,
                               *['ADD'] +
-                              _kwopts(kw, ['tunnel', 'keepalive', 'cork']) +
+                              _kwopts(kw, ['tunnel', 'keepalive',
+                                           'key', 'cork', 'mobile']) +
                               [peer] +
                               list(addr)))
   def addr(me, peer):