[IPython-User] Stdout not immediately appearing using %run in IPython 0.10.1

Fernando Perez fperez.net@gmail....
Mon Oct 18 19:17:13 CDT 2010


On Sun, Oct 17, 2010 at 11:13 AM, Wes McKinney <wesmckinn@gmail.com> wrote:
> I confirmed this problem on the stock Python 2.6.5 bundled with Ubuntu
> 10.04. Same issue if you call the built-in execfile instead of %run--
> and sys.stdout is the only thing affected (if i change print to
> sys.stderr.write(...) then that's fine).

It seems to be a curses bug in Python itself, not an IPython-specific issue:

uqbar[~]> cat bufferbug.py
"""Strange bug in buffering of sys.stdout after calling curses functions.
"""
import time
import curses

def bug():
    curses.initscr()
    curses.endwin()

def f(n=2):
    s = 0.75
    for i in range(n):
        print i
        time.sleep(s)
    print i+1

if __name__ == '__main__':
    f()
    print 'Calling bug() now!'
    bug()
    f()

####

Just run with python, no ipython involved, and you'll see the problem.

This is very annoying: we need to use curses to determine window size,
and this bug seems to persist.  So once we've called curses once,
we're stuck with the problem.

The good news:  I just tested, and 3.1 doesn't show the problem.
The bad news:  I just tested, and 2.7 does show the problem.

Care to file a bug report with python itself?  Who knows, there might
be a fix for the 2.7 series at least...

I've spent a fair amount of time trying to find anything I could call
in curses to work around this, but so far without success.  If anyone
knows of something we could do from our side (rather than just waiting
for Python itself to get fixed or to be all on Python3) by all means
let us know.

Cheers,

f


More information about the IPython-User mailing list