Skip to content

Allowing KeyboardInterrupt to reach a #[pyfunction] #3795

Answered by adamreichold
fgimian asked this question in Questions
Discussion options

You must be logged in to vote

The Python interpreter will catch signals and queue them internally and hence you would need to periodically call Python::check_signals to surface them. Which of course you cannot while you block in WaitForSingleObject.

I think generally speaking if you want timely interrupts via SIGINT, you'll need to restructure your code to expect multiple event sources, e.g. use WaitForMultipleObjects and have an additional event to signal cancellation. You can then run this stuff on a background thread, poll check_signals on the main thread and signal the background thread when you are interrupted. (Or if you use Python's built-in mechanism for waiting on the background thread, you could probably avo…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@adamreichold
Comment options

Answer selected by fgimian
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants