<br><br><div class="gmail_quote">On Fri, May 18, 2012 at 4:17 AM, Mike Winter <span dir="ltr">&lt;<a href="mailto:miwinter@cisco.com" target="_blank">miwinter@cisco.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">half async/half sync is not as obscure as you may think:<div><br></div><div><span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;font-weight:normal;line-height:15px;color:rgb(102,102,102);text-transform:none;font-size:small;white-space:normal;font-family:arial,sans-serif;word-spacing:0px"></span><div>
<span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;display:inline!important;font-weight:normal;float:none;line-height:15px;color:rgb(0,153,51);text-transform:none;font-size:small;white-space:normal;font-family:arial,sans-serif;word-spacing:0px"><a href="http://www.cs.wustl.edu/%7E" target="_blank">www.cs.wustl.edu/~</a></span><b style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;line-height:15px;color:rgb(0,153,51);text-transform:none;font-size:small;white-space:normal;font-family:arial,sans-serif;word-spacing:0px">schmidt</b><span style="text-indent:0px;letter-spacing:normal;font-variant:normal;text-align:-webkit-auto;font-style:normal;display:inline!important;font-weight:normal;float:none;line-height:15px;color:rgb(0,153,51);text-transform:none;font-size:small;white-space:normal;font-family:arial,sans-serif;word-spacing:0px">/PDF/PLoP-95.pdf</span></div>
<div><font color="#009933" face="arial, sans-serif"><span style="line-height:15px"><br></span></font><div><div><div class="h5"><div>On May 17, 2012, at 12:06:04PM, Andrew Francis wrote:</div><br></div></div><blockquote type="cite">
<div><div class="h5"><div><div style="font-size:12pt;font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif"><div><span style="font-size:12pt">Message: 1</span><br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif">
<div style="font-size:12pt;font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif">Date: Thu, 17 May 2012 00:58:57 +0200<br>From: Louis &lt;<a href="mailto:spalax@gresille.org" target="_blank">spalax@gresille.org</a>&gt;<br>
Subject: [Twisted-Python] Synchronous calls using Twisted?<br>To: <a href="mailto:twisted-python@twistedmatrix.com" target="_blank">twisted-python@twistedmatrix.com</a><br>Message-ID: &lt;<a href="mailto:4FB43131.2030805@gresille.org" target="_blank">4FB43131.2030805@gresille.org</a>&gt;<br>
Content-Type: text/plain; charset=ISO-8859-1<br><br>&gt;  Hello,<br>&gt;  I am writing
 an application, which architecture is (I hope my<br>&gt;beautiful drawing is not messed up):<br><br>&gt;  +-------------+   +------------+   +-----------+<br>&gt;  | Core Server |---| Web Server |---| Web client|<br>&gt;  +-------------+   +------------+   +-----------+<br>
&gt;...</div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt"><br>&gt;  Do you think Twisted is the right tool for my use case, or am I doing<br>&gt;an ugly hack to do what I want, which means I should rather use another<br>
&gt;tool?<br><br> </div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">I am not sure why inline generators won&#39;t work?</div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">
<br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">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. </div>
<div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt"><br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt"> 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 &quot;Half-sync/Half-async.&quot;</div>
<div><br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">Essentially one does the following:</div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">
<br></div><div><span style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px">def <b style="background-image:initial;background-color:rgb(255,255,102);background-repeat:initial initial">blockOn</b>(deferred): </span><br style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px">
<span style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px">    ch = <b style="background-image:initial;background-color:rgb(255,255,102);background-repeat:initial initial">stackless</b>.channel() </span><br style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px">
<span style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px">    def cb(result): </span><br style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px"><span style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px">        ch.send(result) </span><br style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px">
<span style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px">    deferred.addBoth(cb) </span><br style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px"><span style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px">    return ch.receive() </span><br style="font-family:verdana,geneva,helvetica,arial,sans-serif;font-size:13px">
</div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt"><br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">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&#39;t feel like installing Stackless Python, then you can use stackless.py (not the new version that
 uses continuations) with the greenlet package.</div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt"><br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">
Here is a link to a complete example</div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt"><br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">
<a href="http://andrewfr.wordpress.com/2011/11/30/the-santa-claus-problem-with-join-patterns/" target="_blank">http://andrewfr.wordpress.com/2011/11/30/the-santa-claus-problem-with-join-patterns/</a><br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">
<br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">Cheers,</div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">Andrew</div>
<div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt"><br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt"><br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt">
<br></div><div style="font-family:&#39;times new roman&#39;,&#39;new york&#39;,times,serif;font-size:12pt"><br></div> </div>  </div></div></div></div><div class="im">_______________________________________________<br>Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br><a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</div></blockquote></div><br></div></div></div><br>_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
<br></blockquote></div><br><br>Hi Andrew<br><br>    What is the advantage of using stackless with twisted? <br><br>Regards<br><br>gelin yan<br>