Skip to content

Conversation

@jholveck
Copy link
Contributor

At the same time as @BoboTiG merged #467, I realized there's a better implementation. Passes pytest and check.sh.

In the XShmGetImage backend, there was a window of time during which a
KeyboardInterrupt (or other asynchronous exception) would cause
cleanup of the MSS object to raise a different exception.  This is one
of the slower parts of this backend, so it's a time when asynchronous
exceptions can hit pretty easily.

While a Python library almost never can guarantee correctness
following an asynchronous exception, ending a program with Ctrl-C is
not uncommon.  We can't guarantee correctness in all circumstances,
and shouldn't try to.

All this patch does is to avoid the exception that may be hard for an
end user to understand.  Instead, the top-level user code will now see
the KeyboardInterrupt, and not the seemingly-unrelated cleanup
exception.
I just learned that memoryviews can be used as context managers, and
release their buffers at the end of that, instead of having to be
GC'd.
@BoboTiG BoboTiG merged commit 9637209 into BoboTiG:main Jan 28, 2026
21 checks passed
@jholveck jholveck deleted the feat-xshmgetimage-exception-buffer branch January 28, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants