-
Notifications
You must be signed in to change notification settings - Fork 302
Description
Restarting a kernel only kills the direct child, but not any opened subprocesses of that child.
This is a problem if the kernel spawns multiple childprocess like the R kernel (on windows: R - cmd - R - cmd - Rterm) or if the python kernel opens a subprocess which sleeps.
Issue on the irkernel repo: IRkernel/IRkernel#226
IMO the kernel manager should kill the complete process group and not only the process which is directly spawned by the kernel manager.
I use restart kernel when I want resources back which I lost in the kernel (due to the stupid commands I executed) and currently I have a 4 processes running (cmd - R - cmd - Rterm) where I killed the kernel 15min ago (and it's still 25% CPU and 1GB Ram). So if I have to wait for the actual process which does the work to finish, the restart command is kind of useless :-(
reproducible example (at least on windows): put it into a cell, execute it and then restart the kernel via the notebook UI.
import platform
import subprocess
if platform.system() == 'Windows':
CREATE_NO_WINDOW = 0x08000000
subprocess_creation_flags = CREATE_NO_WINDOW
else:
# Apparently None won't work here
subprocess_creation_flags = 0
exec_line = u"""python -c "import time;time.sleep( 50000 )" """
p = subprocess.Popen(exec_line, shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
creationflags=subprocess_creation_flags)
p.communicate()