Set event manual reset flag to true #1073
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, a long-running C Python module executed on Windows in a Jupyter kernel can only be interrupted by sending twice the "Interrupt kernel" signal.
This happens because the first interrupt signal is intercepted by
ipykernel/parentpoller.py
and as it is set to auto-reset, it will not reach a C Python module listening for the same signal. At the time, theinterrupt_main()
call scheduled byipykernel/parentpoller.py
will not be executed as the main Python thread is blocked by the long-running C Python module.Only when the "Interrupt kernel" is issued again the C Python module will be interrupted.
This PR sets the
CreateEvent
bManualReset
Boolean flag totrue
, thus requiring the interrupt event to be manually reset by the receiver. This makes it possible for a listening C Python module to be reached by the signal and hence be interrupted, without requiring the interrupt signal to be issued twice.This can be conveniently tested through the attached
waitloop
test Python module, which can be installed on all platforms supported by Jupyter by unzipping waitloop_module.zip and then runningpip install .
in thewaitloop_module
directory:Python interpreter - all platforms
Jupyter notebook - Windows platform
Jupyter notebook - non-Windows platforms
WIth the current Jupyter version, on Windows it is necessary to issue "Interrupt kernel" twice to interrupt
waitloop
, whereas on non-Windows platforms it is sufficient to issue the command once,After merging this PR and the sister PR #1434 in the
ipykernel
repo, a single "Interrupt kernel" will stopwaitloop
also on Windows, as expected.