[Twisted-Python] How to force synchronous behavior

Pedro Sanchez psanchez at nortel.com
Fri Oct 28 17:40:21 EDT 2005


I want to encapsulate deferreds into a function that looks like
synchronous when invoked. Something like this:

def mySyncFunc()
   x = 0
   def done(data):
      global x
      x = data

   d = someCalculation()
   <something here to hold until "done" is really done>
   return x

print mySyncFunc()

someCalculation() returns a deferred (for instance to accesses a DB).
So, how can I write mySyncFunc() so that at the end I print the result
of someCalculation() and not just 0? 



More information about the Twisted-Python mailing list