1.1.1rc RuntimeError: underlying C/C++ object has been deleted

John Hunter wrote:

···

On Wed, Mar 28, 2012 at 8:57 AM, Neal Becker > <ndbecker2@...149...> wrote:

qt-x11-4.8.0-7.fc16.x86_64
PyQt4-4.8.6-1.fc16.x86_64

But interestingly, I'm not actually using the display in this script. I'm
using
pdfpages.

At the beginning of your script (before importing pylab/pyplot) you should
be doing

import matplotlib
matplotlib.use('pdf')

It looks like you are inadvertently importing the qt library in a headless
script run.

JDH

Thanks, but should that cause a (scary looking) error? Or is there a real
problem?

It’s just a clean up error in the qt destructors I think. You are basically in an unsupported use case: using a gui backend, but not raising the figures with show, so our initialization code doesn’t get run properly, which means the clean up may not be properly configured. Our work is hard enough supporting all the GUI toolkits across multiple operating systems – I don’t know that we want to get into trying to support unsupported use cases.

JDH

···

On Wed, Mar 28, 2012 at 1:22 PM, Neal Becker <ndbecker2@…149…> wrote:

import matplotlib

matplotlib.use(‘pdf’)

It looks like you are inadvertently importing the qt library in a headless

script run.

JDH

Thanks, but should that cause a (scary looking) error? Or is there a real

problem?

True that this is probably an unsupported use-case, but I don’t see it as a totally unreasonable one. For example, in many of my scripts in one of my projects, I have command-line options to determine if I am going to save the figure to a file and another option to determine if I am going to show the figure as well. I could run these scripts with or without showing a figure. By the time I process the command-line arguments, I have already imported matplotlib. Of course, it isn’t very difficult to recode it to import and select a backend according to the command-line arguments, it would be a more convoluted script that way.

Note, I have not noticed any issues with this approach while using TkAgg and GTKAgg. I guess it could probably be made into a low-priority TODO item in PyQt4 to see if the destructor is being over-zealous. Neal, your best bet would be to file a wishlist item and tag it as such. Again, low priority, but maybe someone will notice something obvious at a later time.

Cheers!
Ben Root

···

On Wed, Mar 28, 2012 at 2:36 PM, John Hunter <jdh2358@…552…149…> wrote:

On Wed, Mar 28, 2012 at 1:22 PM, Neal Becker <ndbecker2@…149…> wrote:

import matplotlib

matplotlib.use(‘pdf’)

It looks like you are inadvertently importing the qt library in a headless

script run.

JDH

Thanks, but should that cause a (scary looking) error? Or is there a real

problem?

It’s just a clean up error in the qt destructors I think. You are basically in an unsupported use case: using a gui backend, but not raising the figures with show, so our initialization code doesn’t get run properly, which means the clean up may not be properly configured. Our work is hard enough supporting all the GUI toolkits across multiple operating systems – I don’t know that we want to get into trying to support unsupported use cases.

JDH