Skip to content

gh-144748: Make PyErr_CheckSignals raise the exception scheduled by PyThreadState_SetAsyncExc#145178

Open
encukou wants to merge 7 commits intopython:mainfrom
encukou:setasyncexc-interrupts
Open

gh-144748: Make PyErr_CheckSignals raise the exception scheduled by PyThreadState_SetAsyncExc#145178
encukou wants to merge 7 commits intopython:mainfrom
encukou:setasyncexc-interrupts

Conversation

@encukou
Copy link
Member

@encukou encukou commented Feb 24, 2026

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

This looks pretty good. Some non-blocking comments/questions below.

Comment on lines +1444 to +1445
_PyErr_SetNone(tstate, exc);
Py_DECREF(exc);
Copy link
Member

Choose a reason for hiding this comment

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

What happens if exc is an exception instance, rather than a class? Is PyThreadState_SetAsyncExc supposed to support that?

Copy link
Member Author

Choose a reason for hiding this comment

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

The usual C error checking message:

SystemError: _PyErr_SetObject: exception InjectedException() is not a BaseException subclass

Supporting instances would be a reasonable feature, but I haven't seen anyone asking for it.

self.assertEqual(result, 1)

for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
signal.pthread_kill(thread.ident, signal.SIGUSR1)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this has trouble on some systems. Looking at other tests, we might need to run this code in a subprocess?

Copy link
Member Author

Choose a reason for hiding this comment

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

Checked on a Mac: it's trying to pthread_kill a thread that already exited 🤦

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.

2 participants