bizarre print statement hang on Ubuntu?

I have been trying to figure out why my
matplotlib graphs were not posting (fully) to
a wxAUINotebook (see other thread) under Ubuntu
until I moved my cursor out of the frame, but were
fine under Windows. The tentative answer strikes
me as bizarre, but maybe I am misunderstanding
something.

It's the print statements. (It seems).

Attached are two smallish (245 lines) sample
apps that are identical other than that one has all
the print statements commented out. These are
smaller versions of my original code (so excuse the
detritus). The one which includes uncommented print
statements will hang in the same way that I had been
experiencing this issue. To demonstrate the issue:

1. Run these on Ubuntu 8.10 (I'm using 64bit version).
    (requires matplotlib and numpy of course). The
    problem does not happen on WinXP. Haven't tested
    on Mac.

2. Run the one with the print statements, as indicated
    by the filename. DO NOT MOVE THE CURSOR
    OUTSIDE THE FRAME in order to test this properly.
    Press the button to add graphs. On my system (see
    below for full stats) I can only add 5 graphs before it
    hangs, and then I can get it to resume processing
    and post a graph if I bring the cursor outside the
    frame. Not good. Oddly, moving it outside the frame
    will buy you 5 more graphs' worth before it hangs
    again and requires this reset trick.

3. Now run the one with the print statement
     commented out. Now add graphs. With this I have
     been able to add 110 graphs before I got tired.
     Good! (and in my real app, I can use it with an sqlite
     database and a more complex graph and added 40+ of
     those, too).

4. In fact, if you want to vary how many graphs you can
     get before it hangs, just either comment out or copy
     and add more of these print statements. Every 1-2
     print statements subtracted buys you a graph or two
     more before it requires this "reset" of leaving the frame.

Why does having or not having the print statements
make such a huge difference? There is nothing even
in those functions where they are that is very Python
intense, just basic stuff. And why does this hang like
this only under Ubuntu and not at all with WinXP?

Thanks for any help. I hope in understanding this I
will learn some new angle on wxPython or Python. I
had been using print statements to help in debugging,
and they have never been a problem before.

The system I am testing this on:
Ubuntu 8.10
Linux kernel 2.6.27-11-generic
GNOME 2.24.1
2 GB RAM
Dual core 1.8 Ghz
matplotlib 0.98.3
wxPython 2.6.3.2 (I thought it should be
  2.8.x.x but this is what shell is telling me)

Thanks very much,
Che

sample_with_prints.py (10 KB)

sample_without_prints.py (10 KB)

C M wrote:

I have been trying to figure out why my
matplotlib graphs were not posting (fully) to
a wxAUINotebook (see other thread) under Ubuntu
until I moved my cursor out of the frame, but were
fine under Windows. The tentative answer strikes
me as bizarre, but maybe I am misunderstanding
something.

It's the print statements. (It seems).

Attached are two smallish (245 lines) sample
apps that are identical other than that one has all
the print statements commented out. These are
smaller versions of my original code (so excuse the
detritus). The one which includes uncommented print
statements will hang in the same way that I had been
experiencing this issue. To demonstrate the issue:

1. Run these on Ubuntu 8.10 (I'm using 64bit version).
    (requires matplotlib and numpy of course). The
    problem does not happen on WinXP. Haven't tested
    on Mac.

Can you also duplicate it without any 3rd party packages?

Why does having or not having the print statements
make such a huge difference?

My guess is that stdout is in buffered mode and stdout is being used to feed to some other process, and whatever it is that is reading from your app's stdout is not doing it often enough so the buffer is getting full. On a *nix system when that happens the process on the sending side of the pipe is put to sleep until the buffer is emptied.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!