Dear Benjamin, <br><br>Thanks for your answer. My point is that this behavior of delaying or holding the output doesn't happen in python or regular ipython only in qtconsole. Requesting that people call sys.stdout.flush is fine for people who's job it is to build code, though still annoying IMHO. But it is too much to ask many python users. My understanding is that ipython's goal is to lower the barrier of entry, and allow python to compete with matlab and mathematica on the simplicity and interactivity. In that respect, I feel like if there is something to be found about what is holding the output from being flushed, it would be great to find it.<br>

<br>Best, <br>Jonathan<br><br><div class="gmail_quote">On Thu, Mar 29, 2012 at 1:31 PM, MinRK <span dir="ltr"><<a href="mailto:benjaminrk@gmail.com" target="_blank">benjaminrk@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br><br><div class="gmail_quote"><div>On Thu, Mar 29, 2012 at 11:08, Jonathan Rocher <span dir="ltr"><<a href="mailto:jrocher@enthought.com" target="_blank">jrocher@enthought.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



Dear all, <br><br>I am observing an issue on the qtconsole. I am happy to file a bug if it is indeed a new one. I couldn't find a filed bug that describe the same thing though I may have missed it. <br><br>I am running ipython from a version of the trunk that is 2 days old.<br>




<br>When I run the simple code below (needs traits), and modify in the UI the filename field, I do NOT get the output to the console from the print statement due to the fact that the filename has changed at the first key stroke. And I get TWO at the second key stroke. This may sound like a minor issue but in a more realistic situation (module available upon request), the same issue evolves into a delay on every key stroke, the last one being always held by ipython. This can be disturbing when developing, if people use print statements to debug. <br>



</blockquote><div><br></div></div><div>This is a matter of sys.stdout.flush().  Just like `print` in regular Python/IPython does not write to the terminal until sys.stdout.flush() is called, stdout messages are not published to frontends until then as well.  I can't tell you *why* the internals of Python are not calling flush on the first print but are on the rest, but the answer if you want to ensure that print statements happen immediately is always: call sys.stdout.flush() yourself.  This is true in all Python programs, but seems to come up more often in the IPython kernel.</div>

<div>

<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>When exiting the qtconsole after running the larger version of the module triggering the issue I also got the following error message (nothing more oddly enough):<br><span style="font-family:courier new,monospace">Exception in thread Thread-2 (most likely raised during interpreter shutdown):Exception in thread Thread-3 (most likely raised during interpreter shutdown):</span><br style="font-family:courier new,monospace">




<span style="font-family:courier new,monospace">Traceback (most recent call last):Traceback (most recent call last):</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">  File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/threading.py", line 552, in __bootstrap_inner</span><br style="font-family:courier new,monospace">




<span style="font-family:courier new,monospace">  File "/Users/jrocher/Projects/Ipython_trunk/ipython/IPython/zmq/kernelmanager.py", line 441, in run</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">  File "/Users/jrocher/Projects/Ipython_trunk/ipython/IPython/zmq/kernelmanager.py", line 121, in _run_loop</span><br style="font-family:courier new,monospace">




<span style="font-family:courier new,monospace">  File "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/zmq/eventloop/ioloop.py", line 300, in start</span></blockquote><div><br></div>



</div><div>This is probably not a real issue, just a result of Python shutdown cleaning up namespaces too aggressively so that the code that silences clean-exit exceptions has been removed before the background threads can use it.  I don't know how to clean this up, but it's not anything other than a cosmetic issue at shutdown.</div>



<div><br></div><div>-MinRK</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br><br>Let me know if you have questions or if I can go ahead and file this bug.<br>




<br>Best, <br>Jonathan<br><br><br>########################## IOLOOP_ISSUE MODULE ##############################<br><br>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">""" Displays a stdout issue in ipython qtconsole trunk. Modifying the filename </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">doesn't trigger a print statement. The second key stroke triggers 2.</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">"""</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">from traits.api import HasTraits, Str</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">class ExerciseShell(HasTraits):</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    """ Build a new ipython notebook with extended metadata to contain a </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    CanopyExercise.</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    """</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    filename = Str()</p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    def _filename_changed(self):</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        print "filename changed!"</p>

<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">if __name__ == "__main__":</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    e = ExerciseShell()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    e.configure_traits()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">################################### EOF ########################################</p><span><font color="#888888"><br>

<br>-- <br>Jonathan Rocher, PhD<br><span style="color:rgb(102,102,102)">Scientific software developer</span><br>
<font color="#888888"><span>Enthought</span>, Inc.<br>
<a href="mailto:jrocher@enthought.com" target="_blank">jrocher@<span>enthought</span>.com</a><br>
<a href="tel:1-512-536-1057" value="+15125361057" target="_blank">1-512-536-1057</a><br>
<a href="http://www.enthought.com/" target="_blank">http://www.<span>enthought</span>.com</a></font><br><div style="display:inline"></div><br>
</font></span><br></div>_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
<br></blockquote></div><br>
<br>_______________________________________________<br>
IPython-dev mailing list<br>
<a href="mailto:IPython-dev@scipy.org" target="_blank">IPython-dev@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/ipython-dev" target="_blank">http://mail.scipy.org/mailman/listinfo/ipython-dev</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Jonathan Rocher, PhD<br><span style="color:rgb(102,102,102)">Scientific software developer</span><br><font color="#888888"><span>Enthought</span>, Inc.<br>
<a href="mailto:jrocher@enthought.com" target="_blank">jrocher@<span>enthought</span>.com</a><br>
<a href="tel:1-512-536-1057" value="+15125361057" target="_blank">1-512-536-1057</a><br>
<a href="http://www.enthought.com/" target="_blank">http://www.<span>enthought</span>.com</a></font><br><div style="display:inline"></div><br>