[IPython-dev] [BUG] stdout issue in qtconsole

Jonathan Rocher jrocher at enthought.com
Thu Mar 29 21:33:42 EDT 2012


Dear Benjamin,

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.

Best,
Jonathan

On Thu, Mar 29, 2012 at 1:31 PM, MinRK <benjaminrk at gmail.com> wrote:

>
>
> On Thu, Mar 29, 2012 at 11:08, Jonathan Rocher <jrocher at enthought.com>wrote:
>
>> Dear all,
>>
>> 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.
>>
>> I am running ipython from a version of the trunk that is 2 days old.
>>
>> 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.
>>
>
> 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.
>
>
>>
>> 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):
>> Exception in thread Thread-2 (most likely raised during interpreter
>> shutdown):Exception in thread Thread-3 (most likely raised during
>> interpreter shutdown):
>> Traceback (most recent call last):Traceback (most recent call last):
>>   File
>> "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/threading.py",
>> line 552, in __bootstrap_inner
>>   File
>> "/Users/jrocher/Projects/Ipython_trunk/ipython/IPython/zmq/kernelmanager.py",
>> line 441, in run
>>   File
>> "/Users/jrocher/Projects/Ipython_trunk/ipython/IPython/zmq/kernelmanager.py",
>> line 121, in _run_loop
>>   File
>> "/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/zmq/eventloop/ioloop.py",
>> line 300, in start
>
>
> 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.
>
> -MinRK
>
>
>>
>>
>> Let me know if you have questions or if I can go ahead and file this bug.
>>
>> Best,
>> Jonathan
>>
>>
>> ########################## IOLOOP_ISSUE MODULE
>> ##############################
>>
>> """ Displays a stdout issue in ipython qtconsole trunk. Modifying the
>> filename
>>
>> doesn't trigger a print statement. The second key stroke triggers 2.
>>
>> """
>>
>> from traits.api import HasTraits, Str
>>
>>  class ExerciseShell(HasTraits):
>>
>> """ Build a new ipython notebook with extended metadata to contain a
>>
>> CanopyExercise.
>>
>> """
>>
>> filename = Str()
>>
>> def _filename_changed(self):
>>
>> print "filename changed!"
>>
>> if __name__ == "__main__":
>>
>> e = ExerciseShell()
>>
>> e.configure_traits()
>>
>>  ################################### EOF
>> ########################################
>>
>>
>> --
>> Jonathan Rocher, PhD
>> Scientific software developer
>> Enthought, Inc.
>> jrocher at enthought.com
>> 1-512-536-1057
>> http://www.enthought.com
>>
>>
>> _______________________________________________
>> IPython-dev mailing list
>> IPython-dev at scipy.org
>> http://mail.scipy.org/mailman/listinfo/ipython-dev
>>
>>
>
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev
>
>


-- 
Jonathan Rocher, PhD
Scientific software developer
Enthought, Inc.
jrocher at enthought.com
1-512-536-1057
http://www.enthought.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20120329/32ea2f99/attachment.html>


More information about the IPython-dev mailing list