Skip to content

Fix callback cleanup while signals are blocked - #32691

Open
hector2394 wants to merge 1 commit into
matplotlib:mainfrom
hector2394:fix/callback-registry-blocked-cleanup
Open

hector2394 wants to merge 1 commit into
matplotlib:mainfrom
hector2394:fix/callback-registry-blocked-cleanup

Conversation

@hector2394

Copy link
Copy Markdown

PR summary

Closes #32674.

A listener collected inside CallbackRegistry.blocked() can raise an unraisable KeyError and leave a dead weak reference in the registry. Blocking currently replaces the callback mapping, which weakref cleanup still needs to access.

This change keeps registrations available and checks the blocked signals in process(). Nested blocks restore their previous blocking state on exit, and pickling excludes temporary blocking state.

Regression tests cover listener cleanup during global and selective blocks, connecting and disconnecting within nested blocks, and pickling while blocked.

The full test_cbook.py module and targeted color, colorbar and contour callback tests passed. Five optional pandas and xarray cases were skipped. The editable build, Ruff and mypy checks also passed.

AI Disclosure

AI agents generated the implementation, regression tests and ran the local checks. I reviewed the code before doing the commit and push.

PR quality check

  • Use an expressive title
  • New and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New features and API changes have release notes
  • [N/A] Documentation complies with the documentation guidelines

Keep callback registrations available to weakref cleanup while dispatch is blocked.
@github-actions

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Weakly held listener garbage-collected inside CallbackRegistry.blocked() raises KeyError in _remove_proxy

1 participant