matplotlib hanging on Mac OS 10.7 with Python 2.7.2 EPD 7.2-2 (64-bit)

Dear Python gurus,

I have written the attached script to plot data from SAMP interaction with TOPCAT (http://www.star.bris.ac.uk/~mbt/topcat/).

I select a row on a given table (VOtable format) in TOPCAT, got the message

Selected : file:/Volumes/pepperland/erosdata/cc_all/tm_all.vot 18

Plotting star tm5000k7768

All I obtain on screen is a blank rectangle window without borders and the rainbow wheel. I sampled the python process, file attached as well.

I updated PyQt4 using the latest Mac snapshot and the Qt 4.8 libraries.

Any hint welcome, thanks.

Cheers,

Jean-Baptiste Marquette

PlotSAMP.py (3.55 KB)

Sampling.txt (96.1 KB)

Jean,

You have several possible sources of problems here. I would first make sure that basic matplotlib scripts work using the Qt4Agg backend on your computer. Test out some regular scripts from the examples section of the documentation. If they work as expected, then it is probably more likely that there is a problem with one of the other libraries. Another possible source of trouble may lie with the calls to “sleep”. Because the display libraries are not on a separate process, the sleep could also prevent the figures from being completely rendered.

Personally, I wouldn’t even bother with the interactive mode. Keep it off, and just put the cleanup code after “plt.show()”, which is a blocking call. There is no need to implement your own event loop.

Ben Root

···

On Thu, Mar 1, 2012 at 10:59 AM, Jean-Baptiste Marquette <marquett@…3605…> wrote:

Dear Python gurus,

I have written the attached script to plot data from SAMP interaction with TOPCAT (http://www.star.bris.ac.uk/~mbt/topcat/).

I select a row on a given table (VOtable format) in TOPCAT, got the message

Selected : file:/Volumes/pepperland/erosdata/cc_all/tm_all.vot 18

Plotting star tm5000k7768

All I obtain on screen is a blank rectangle window without borders and the rainbow wheel. I sampled the python process, file attached as well.

I updated PyQt4 using the latest Mac snapshot and the Qt 4.8 libraries.

Any hint welcome, thanks.

Cheers,

Jean-Baptiste Marquette

Hi Ben,

You have several possible sources of problems here. I would first make sure that basic matplotlib scripts work using the Qt4Agg backend on your computer. Test out some regular scripts from the examples section of the documentation. If they work as expected, then it is probably more likely that there is a problem with one of the other libraries.

Good point. Tests successful.

Another possible source of trouble may lie with the calls to “sleep”. Because the display libraries are not on a separate process, the sleep could also prevent the figures from being completely rendered.

Personally, I wouldn’t even bother with the interactive mode. Keep it off, and just put the cleanup code after “plt.show()”, which is a blocking call. There is no need to implement your own event loop.

The challenge is to display hundreds of stellar light curves by sequently selecting rows in a table through the SAMP mechanism. Thus it would be fine not to have to kill the plot window after each display, but to have it automatically refreshed after each row selection (I’m a lazy guy…).

I just commented the plt.ion() line, this yields a segmentation fault, here is the crash report.

Cheers

JB

python_2012-03-02-115756_MacProJB.crash (59.8 KB)

Hi Ben,

You have several possible sources of problems here. I would first make
sure that basic matplotlib scripts work using the Qt4Agg backend on
your computer. Test out some regular scripts from the examples section
of the documentation. If they work as expected, then it is probably
more likely that there is a problem with one of the other libraries.

Good point. Tests successful.

Another possible source of trouble may lie with the calls to "sleep".
Because the display libraries are not on a separate process, the sleep
could also prevent the figures from being completely rendered.

Personally, I wouldn't even bother with the interactive mode. Keep it
off, and just put the cleanup code after "plt.show()", which is a
blocking call. There is no need to implement your own event loop.

The challenge is to display hundreds of stellar light curves by
sequently selecting rows in a table through the SAMP mechanism. Thus it
would be fine not to have to kill the plot window after each display,
but to have it automatically refreshed after each row selection (I'm a
lazy guy…).
I just commented the plt.ion() line, this yields a segmentation fault,
here is the crash report.

This appears to be very much a dueling event loop problem. My guess is that the solution will have to be something that keeps the event loops well separated, probably in separate processes. All interaction with your Client event loop would be in one process, and the callback would get your data and put it somewhere (e.g. in a numpy npz file). Then the trick is to have the matplotlib process in a polling loop using a timer (done crudely with plt.pause(0.1); there is probably a better way) checking to see if that "somewhere" has been updated, and if so, updating its plot.

Eric

···

On 03/02/2012 01:16 AM, Jean-Baptiste Marquette wrote:

Cheers
JB

Aloha Eric,

This appears to be very much a dueling event loop problem. My guess is
that the solution will have to be something that keeps the event loops
well separated, probably in separate processes. All interaction with
your Client event loop would be in one process, and the callback would
get your data and put it somewhere (e.g. in a numpy npz file). Then the
trick is to have the matplotlib process in a polling loop using a timer
(done crudely with plt.pause(0.1); there is probably a better way)
checking to see if that “somewhere” has been updated, and if so,
updating its plot.

I feel I see the light at the end of the tunnel. The npz file is even not necessary, I just need to pass the star id to a separate plotting process, to be compared to some stored previous value, in order to refresh the plot.

I have to think about it for a couple of days…

Thanks for the suggestion,

Cheers,

JB

A hint. Not a solution. No guarantee.

With Tkinter, a similar problem arises if Tkinter calls are made from another thread than those one which imported Tkinter. At least on OS X 10.6, the program will be unreliable, crashing after unpredictable time with similar symptoms to that you diagnosed. The Tkinter window will no longer update, even if Tkinter calls are made, and probably even if from the Tkinter importing thread. If one makes some inputs, iirc, the rainbow wheen appears.

I am well aware of that this is isn’t Tkinter. It’s a guess, as I said, and meant as a pointer to the root which can lead, in Tkinter, but maybe also in PyQt, to such problems.

A solution is to message the main thread via thread shared objects. The main thread needs to poll them then. With Tkinter this is relatively easy to implement, but I have no idea about what it would look like in PyQt.

It might well be that all this here is utter nonsense and leads nowhere. But since noone else has emphatic suggestions I thought I spend my 2 Ct.

Friedrich

···

Am 01.03.2012 um 17:59 schrieb Jean-Baptiste Marquette <marquett@…3605…>:

Dear Python gurus,

I have written the attached script to plot data from SAMP interaction with TOPCAT (http://www.star.bris.ac.uk/~mbt/topcat/).

I select a row on a given table (VOtable format) in TOPCAT, got the message

Selected : file:/Volumes/pepperland/erosdata/cc_all/tm_all.vot 18

Plotting star tm5000k7768

All I obtain on screen is a blank rectangle window without borders and the rainbow wheel. I sampled the python process, file attached as well.

I updated PyQt4 using the latest Mac snapshot and the Qt 4.8 libraries.

Any hint welcome, thanks.