def in_reactor(f):
 def wrap(*args, **kwargs):
  from twisted.internet import reactor, defer
  result = []
  def async():
   d = defer.maybeDeferred(f, *args, **kwargs)
   @d.addErrback
   def eb(f):
    f.printTraceback()
   @d.addBoth
   def do_stop(r):
    result.append(r)
    reactor.stop()
  reactor.callWhenRunning(async)
  reactor.run()
  return result[0]
 wrap.__doc__ = f.__doc__
 wrap.__name__ = f.__name__
 wrap._orig = f
 return wrap

def in_reactor ( f ) : def wrap ( * args , ** kwargs ) : from twisted . internet import reactor , defer result = [ ] def async ( ) : d = defer . maybeDeferred ( f , * args , ** kwargs ) @ d . addErrback def eb ( f ) : f . printTraceback ( ) @ d . addBoth def do_stop ( r ) : result . append ( r ) reactor . stop ( ) reactor . callWhenRunning ( async ) reactor . run ( ) return result [ 0 ] wrap . __doc__ = f . __doc__ wrap . __name__ = f . __name__ wrap . _orig = f return wrap
decorate a function by running it with maybedeferred in a reactor .