[Twisted-Python] Writing a wrapper from asynchronous to synchronous

Uwe C. Schroeder uwe at oss4u.com
Fri Feb 24 01:46:03 EST 2006

Hi everyone,

I know someone is going to say it's a flaw in the design - and I partially 
agree with that. However I have an application that allows a fairly 
unexperienced programmer to add modules. What I need to do is to write a 
wrapper that hides the asynchronous nature of pb (well, Twisted that is, but 
I'm only using pb), simply because most programmers at the potential 
customers don't have any knowledge about asynchonous programming.
The API for the modules should hide all communications to the server side. 
So my question would be, is there a way to write some kind of wrapper that 
will make the caller wait for the deferred callback to be invoked?
I have one specific method that just has a flag which is set to true in the 
deferred callaback which then in turn triggers the action required. So 
basically it's a recursive method that get's called via a reactor.callLater 
and if the flag is true calls whatever is needed. The point is to suspend 
execution of a certain method until some prerequisite initializations are 
finished.  I'd like to do that in an as convenient way as possible.
So it's like:

1) module calls some method #1
2) #1 depends on certain initializations to finish
3) the call to #1 doesn't return unless step 2) is done

any smart idea's how to wrap that up?
Any hints are highly appreciated


Open Source Solutions 4U, LLC	1618 Kelly St
Phone:  +1 707 568 3056		Santa Rosa, CA 95401
Cell:   +1 650 302 2405		United States
Fax:    +1 707 568 6416

More information about the Twisted-Python mailing list