Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Kill subprocesses on shutdown. #869

Merged
merged 7 commits into from
Feb 18, 2022
Merged

Conversation

Carreau
Copy link
Member

@Carreau Carreau commented Feb 17, 2022

Fixes jupyter/jupyter_client#104.

This should make sure we properly cull all subprocesses at shutdown,
it does change one of the private method from sync to async in order to
no user time.sleep or thread so this may affect subclasses, though I
doubt it.

It's also not completely clear to me whether this works on windows as
SIGINT I belove is not a thing.

Regardless as this affects things like dask, and others that are mostly
on unix, it should be an improvement.

It does the following, stopping as soon as it does not find any more
children to current process.

  • Send sigint to everything
  • Immediately send sigterm in look with an exponential backoff from
    0.01 to 1 second roughtly multiplying the delay until next send by 3
    each time.
  • Switch to sending sigkill with same backoff.

There is no delay after sigint, as this is just a courtesy.
The delays backoff are not configurable. I can imagine that on slow
systems it may make sens

Fixes #jupyter/jupyter_client#104

This should make sure we properly cull all subprocesses at shutdown,
it does change one of the private method from sync to async in order to
no user time.sleep or thread so this may affect subclasses, though I
doubt it.

It's also not completely clear to me whether this works on windows as
SIGINT I belove is not a thing.

Regardless as this affects things like dask, and others that are mostly
on unix, it should be an improvement.

It does the following, stopping as soon as it does not find any more
children to current process.

 - Send sigint to everything
 - Immediately send sigterm in look with an exponential backoff from
   0.01 to 1 second roughtly multiplying the delay until next send by 3
     each time.
 - Switch to sending sigkill with same backoff.

There is no delay after sigint, as this is just a courtesy.
The delays backoff are not configurable. I can imagine that on slow
systems it may make sens
@Carreau Carreau force-pushed the kill-sp branch 2 times, most recently from 1b53afb to b3e8b85 Compare February 17, 2022 12:36
ipykernel/kernelbase.py Outdated Show resolved Hide resolved
ipykernel/kernelbase.py Outdated Show resolved Hide resolved
Co-authored-by: Steven Silvester <[email protected]>
@@ -1131,9 +1136,62 @@ def _input_request(self, prompt, ident, parent, password=False):
raise EOFError
return value

def _at_shutdown(self):
async def _progressively_terminate_all_children(self):
if sys.platform == "win32":
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this method should work on both Windows and Posix: https://stackoverflow.com/a/25134985

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll give it a try. I know that the "loop and kill children" was switched back to killpg at some point in jupyter_client as the first one had issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

(that was in jupyter/jupyter_client#743, i'll try to get the same logic from there)

@blink1073
Copy link
Contributor

Kicking to make sure we hit all downstream tests

@blink1073 blink1073 closed this Feb 18, 2022
@blink1073 blink1073 reopened this Feb 18, 2022
@blink1073
Copy link
Contributor

Weird. I have no idea why the ipyparallel downstream test is getting skipped in this PR. It didn't get skipped in my PR or in main.

Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

Thanks!

@blink1073 blink1073 merged commit 78c83ad into ipython:main Feb 18, 2022
@Carreau
Copy link
Member Author

Carreau commented Feb 19, 2022

Thanks!

Thanks to you for the review and everything.

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.

subprocesses of kernels are not killed by restart
2 participants