Skip to content

Conversation

tacaswell
Copy link
Member

This can fail if the c++ side of the object has already been cleaned up but the Python side is still lingering (due to refs in callbacks).

closes #29618

I do not think it is worth constructing a test to generate this case, but in the case where I saw it in the wild this fixed the tests locally for me.

PR checklist

@tacaswell tacaswell added this to the v3.10.6 milestone Aug 29, 2025
Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We seem to have an _isdeleted; should we be using that?

if self.height() <= 0 or self.width() <= 0:
return
except RuntimeError:
# This can happen if the c++ object is already cleaned up
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check the error message to ensure we’re not swallowing other potential RuntimeErrors?

Also, are we sure this is the only place that may access the C++ object?

@tacaswell
Copy link
Member Author

We seem to have an _isdeleted; should we be using that?

Yes and than also handles Tim's comment.

This can fail if the c++ side of the object has already been cleaned up
but the Python side is still lingering (due to refs in callbacks).

closes matplotlib#29618
@tacaswell
Copy link
Member Author

I confirmed this also fixes the reproduce I found.

@ksunden
Copy link
Member

ksunden commented Aug 29, 2025

Test failures appear to be related to a new release of coverage:

https://pypi.org/project/coverage/#history

https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst#version-7106--2025-08-29

EDIT: Was not coverage, was pytest-rerunfailures

@ksunden ksunden merged commit a7e81ef into matplotlib:main Aug 29, 2025
48 of 50 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Aug 29, 2025
@tacaswell tacaswell deleted the fix/qt_cleanup branch August 29, 2025 20:55
ksunden added a commit that referenced this pull request Aug 29, 2025
…484-on-v3.10.x

Backport PR #30484 on branch v3.10.x (FIX: be more cautious about checking widget size)
@ksunden ksunden mentioned this pull request Aug 30, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: FigureCanvasQT is seemingly prematurely freed under certain conditions
4 participants