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

L. Daniel Burr ldanielburr at mac.com
Fri Feb 24 13:54:34 EST 2006

On Fri, 24 Feb 2006 10:53:17 -0600, <glyph at divmod.com> wrote:

> On Thu, 23 Feb 2006 22:46:03 -0800, "Uwe C. Schroeder" <uwe at oss4u.com>  
> wrote:
>> Hi everyone,
>> I know someone is going to say it's a flaw in the design
> I would hate to disappoint you.
> "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

[SNIP Glyph explains why this is not a good thing, or even possible]

I'm always fascinated with these kinds of issues, because they come up  
fairly often, and are so illustrative of human nature.  The original  
poster feels that he needs to do X, and is most likely not interested in  
anyone's opinion of the actual desirability/validity of so doing.  And  
yet, what response does his question receive?  A detailed explanation of  
why he should not consider doing X, even though it is clear that X is what  
he feels he must do.

Of course, I agree that X is definitely not something that the original  
poster should contemplate doing; it is just a bad idea, period, and will  
likely result in frustration and disappointment.  However, I think it is  
important to point out that the original poster is most likely pursuing  
this line of inquiry because the possibility of educating his target  
audience is slim, or none.  People are much harder to deal with than  
machines, especially when it comes to learning new things.  Forcing  
twisted to behave synchronously doubtless sounds easier than teaching an  
inexperienced coder how to write twisted-friendly code.

My pointless musings aside, I do have a concrete suggestion for the  
original poster: Create an HTTP server that proxies the pb calls on behalf  
of your programmers.  Let them just post messages to that server, using  
whatever synchronous HTTP client (urllib, etc) they desire.  Not  
technically elegant, no, but far easier than mangling twisted, and far  
easier than trying to teach your programmers how to write async code.   
Note that the server doesn't have to be HTTP, but most programmers have  
some passing acquaintance with it, and client libraries are ubiquitous, so  
it is an easy option.

Hope this helps,

L. Daniel Burr

More information about the Twisted-Python mailing list