Skip to content

Fix inability to interrupt processes on Windows - #12137

Merged
Carreau merged 16 commits into
ipython:masterfrom
itamarst:3400-subprocess-stuck-windows
Feb 27, 2020
Merged

Carreau merged 16 commits into
ipython:masterfrom
itamarst:3400-subprocess-stuck-windows

Conversation

@itamarst

@itamarst itamarst commented Feb 21, 2020 •

Copy link
Copy Markdown
Contributor

Fixes #3400

(or at least fixes the Windows subprocesses variant; there's a bunch of stuff in there that is probably separate tickets—at least pdb was moved out into its own).

It appears that in addition to wait() being uninterruptible (https://bugs.python.org/issue28168), so is read()ing from the subprocess.

Reading is therefore pushed off to threads, and wait() replaced with the equivalent poll()-based loop. If the user interrupts the process, it is killed.

This is demonstrated by a unit test that previously failed, and now passes. Still remaining for me to do is actually test this fix on Windows from Jupyter; I'm waiting for a VM to unpack. If a reviewer wants to try this out themselves, by all means do so :)

@itamarst

itamarst commented Feb 21, 2020 •

Copy link
Copy Markdown
Contributor Author

I now have a process interrupting test that simulates how ipykernel handles interrupts, and it demonstrates that system()-run proceses:

  1. Exit quickly on Linux in response to the interrupt.
  2. Ignore the interrupt on Windows.

@itamarst

itamarst commented Feb 21, 2020 •

Copy link
Copy Markdown
Contributor Author

It appears the subprocess also becomes uninterruptible while reading, not just during wait().

@itamarst itamarst changed the title [WIP] Attempt at fixing inability to interrupt processes Fix inability to interrupt processes on Windows Feb 26, 2020
@itamarst
itamarst marked this pull request as ready for review February 26, 2020 18:48
@itamarst

Copy link
Copy Markdown
Contributor Author

Investigating the Travis failure.

@Carreau Carreau added this to the 7.13 milestone Feb 27, 2020
@Carreau

Carreau commented Feb 27, 2020

Copy link
Copy Markdown
Member

Well you seem to know what you are doing and have a windows machine. I can't test, but the code seem reasonable. Thanks !

@Carreau
Carreau merged commit 1a01864 into ipython:master Feb 27, 2020
meeseeksmachine pushed a commit to meeseeksmachine/ipython that referenced this pull request Feb 27, 2020
Carreau added a commit that referenced this pull request Feb 27, 2020
…137-on-7.x

Backport PR #12137 on branch 7.x (Fix inability to interrupt processes on Windows)
@amrita112

Copy link
Copy Markdown

Should this be working in IPython version 7.15.0? I couldn't get it to work.
I ran the following in a jupyter notebook cell:
input()
and then tried to interrupt the kernel, but couldn't.

@itamarst

Copy link
Copy Markdown
Contributor Author

@amrita112 you also need the newest IPykernel.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kernel/Interrupt Kernel does not terminate stuck subprocesses in the notebook

3 participants