Message: 1

Date: Thu, 17 May 2012 00:58:57 +0200
From: Louis <[email protected]>
Subject: [Twisted-Python] Synchronous calls using Twisted?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

>  Hello,
>  I am writing an application, which architecture is (I hope my
>beautiful drawing is not messed up):

>  +-------------+   +------------+   +-----------+
>  | Core Server |---| Web Server |---| Web client|
>  +-------------+   +------------+   +-----------+
>...

>  Do you think Twisted is the right tool for my use case, or am I doing
>an ugly hack to do what I want, which means I should rather use another
>tool?


I am not sure why inline generators won't work?

Over the years, I use Stackless Python with Twisted. I use Twisted for many of 
the reasons you describe. For myself there is another dimension: I find that a 
lot of the code I write are orchestrations - that is in order to compute 
something, I have to make a few network calls sequentially. 

 I use a technique that Christopher Armstrong (what happened to him?) called a 
blockOn. For the sake of being academic (roll your eyes here),  this is an 
example of an obscure design pattern called "Half-sync/Half-async."

Essentially one does the following:

def blockOn(deferred): 
    ch = stackless.channel() 
    def cb(result): 
        ch.send(result) 
    deferred.addBoth(cb) 
    return ch.receive() 


Of course, there is a bit more, like the Twisted reactor is running in its own 
tasklet. But this has the effect of nicely allowing one to use Twisted in a 
synchronous fashion. If you don't feel like installing Stackless Python, then 
you can use stackless.py (not the new version that uses continuations) with the 
greenlet package.

Here is a link to a complete example

http://andrewfr.wordpress.com/2011/11/30/the-santa-claus-problem-with-join-patterns/


Cheers,
Andrew
_______________________________________________
Twisted-Python mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to