On Fri, May 18, 2012 at 4:17 AM, Mike Winter <miwin...@cisco.com> wrote:
> half async/half sync is not as obscure as you may think: > > www.cs.wustl.edu/~ <http://www.cs.wustl.edu/%7E>*schmidt*/PDF/PLoP-95.pdf > > On May 17, 2012, at 12:06:04PM, Andrew Francis wrote: > > Message: 1 > Date: Thu, 17 May 2012 00:58:57 +0200 > From: Louis <spa...@gresille.org> > Subject: [Twisted-Python] Synchronous calls using Twisted? > To: twisted-python@twistedmatrix.com > Message-ID: <4fb43131.2030...@gresille.org> > 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 > Twisted-Python@twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python > > > > _______________________________________________ > Twisted-Python mailing list > Twisted-Python@twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python > > Hi Andrew What is the advantage of using stackless with twisted? Regards gelin yan
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python