<br><div class="gmail_quote">On Thu, May 26, 2011 at 9:38 AM,  <span dir="ltr">&lt;<a href="mailto:exarkun@twistedmatrix.com">exarkun@twistedmatrix.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
In addition to what Andrew said, I&#39;ll also point out that rather than<br>
making code that expects blocking writes to stdout work by putting<br>
stdout back into blocking mode, you can make it work by instead<br>
providing a stdout which will buffer anything that cannot immediately be<br>
written non-blockingly.  StandardIO gives you exactly this; its `write`<br>
knows how to deal with non-blocking descriptors and buffer as necessary.<br>
This is why manhole doesn&#39;t have the same problem as your code calling<br>
directly into `code.interact`.  For details,<br>
&lt;<a href="http://twistedmatrix.com/trac/browser/trunk/twisted/conch/manhole.py#L45" target="_blank">http://twistedmatrix.com/trac/browser/trunk/twisted/conch/manhole.py#L45</a>&gt;.<br>
<br></blockquote><div><br>Thanks.  I&#39;m having trouble integrating this or Andrew&#39;s idea into my example.  The simplest case doesn&#39;t quite work right for me (I see &#39;&gt;&gt;&gt;&#39; prompts, and can interact with the python interpreter but the banner appears at the end of the REPL after I press Ctrl+D, and then I never see the &#39;&gt;&#39; prompts from my original program anymore)...was this what you had in mind?  See the diff below.<br>
<br><font face="Calibri, sans-serif" size="2"><div>@@ -6,6 +6,7 @@</div>
<div> without blocking the reactor.</div>
<div> &quot;&quot;&quot;</div>
<div> </div>
<div>+import sys</div>
<div> from twisted.internet import stdio</div>
<div> from twisted.protocols import basic</div>
<div> </div>
<div>@@ -22,7 +23,8 @@</div>
<div>         code.interact()</div>
<div> </div>
<div> def main():</div>
<div>-    stdio.StandardIO(Echo())</div>
<div>+    stdio_obj = stdio.StandardIO(Echo())</div>
<div>+    sys.stderr = stdio_obj</div>
<div>     from twisted.internet import reactor</div>
<div>     reactor.run()</div></font><br clear="all"></div></div><br>-- <br>Benjamin<br>