[IPython-User] Delayed printing to stdout in the qtconsole

MinRK benjaminrk@gmail....
Fri Aug 24 15:49:05 CDT 2012


On Fri, Aug 24, 2012 at 12:49 PM, Alejandro Weinstein <
alejandro.weinstein@gmail.com> wrote:

> Hi:
>
> If I call a function that take a while to return, say 5 seconds, the
> print commands in the qtconsole are delayed. Consider for instance the
> following code:
>
> #######################################################
> import numpy as np
>
> def slow_f():
>     '''A function that takes about 4 seconds to run.'''
>     N = 1200
>     A = np.random.rand(N, N)
>     return np.linalg.inv(A)
>
> print 'Calling slow_f for the first time'
> B = slow_f()
> print 'Calling slow_f for the second time'
> C = slow_f()
> print 'Calling slow_f for the third time'
> D = slow_f()
> print 'Done'
> #######################################################
>
> If I run this code in a standard IPython console (or just as $python
> ip.py), I get (the comments are to indicate the timing):
>
> In [2]: run ip.py
> Calling slow_f for the first time      # Wait ~4 seconds
> Calling slow_f for the second time # Wait ~4 seconds
> Calling slow_f for the third time    # Wait ~4 seconds
> Done
>
> However, if I run the same code in the qtconsole, the output is
> In [2]: run ip
> # No output for ~4 seconds
> Calling slow_f for the first time
> Calling slow_f for the second time # These two messages are printed
> together, then after 4 seconds
> Calling slow_f for the third time # Wait ~4 seconds
> Done
>
> Is this different behavior of the qtconsole expected? I'm running the
> current master version of IPython (144f08a).
>

It is expected, in that this is a known deficiency, but it is not exactly
intended.

The difference is that terminal Python writes directly to the terminal,
whereas the two-process Kernel doesn't write until 'stdout.flush' is
called.  There is an implicit flush if two prints are separated by at least
[50ms](
https://github.com/ipython/ipython/blob/master/IPython/zmq/iostream.py#L83),
but the way the logic is written the first print *never* implies a flush.
 I would consider this a bug.

Can you try this branch <https://github.com/ipython/ipython/pull/2335>,
which changes the logic a bit?

-MinRK


> Alejandro.
> _______________________________________________
> IPython-User mailing list
> IPython-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20120824/ccf14fe2/attachment.html 


More information about the IPython-User mailing list