Skip to content

Commit 7d7961e

Browse files
committed
need to be even stricter on windows
1 parent f24a989 commit 7d7961e

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

ipykernel/kernelbase.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,11 @@ async def comm_info_request(self, stream, ident, parent):
802802
self.log.debug("%s", msg)
803803

804804
def _send_interupt_children(self):
805-
806-
pid = os.getpid()
807-
pgid = os.getpgid(pid)
808-
809805
if os.name == "nt":
810806
self.log.error("Interrupt message not supported on Windows")
811807
else:
808+
pid = os.getpid()
809+
pgid = os.getpgid(pid)
812810
# Prefer process-group over process
813811
if pgid and hasattr(os, "killpg"):
814812
try:
@@ -1139,6 +1137,9 @@ def _input_request(self, prompt, ident, parent, password=False):
11391137
return value
11401138

11411139
async def _progressively_terminate_all_children(self):
1140+
if sys.platform != "win32":
1141+
self.log.info(f"Terminating subprocesses not yet supported on windows.")
1142+
return
11421143

11431144
pgid = os.getpgid(os.getpid())
11441145
if not pgid:
@@ -1152,10 +1153,9 @@ async def _progressively_terminate_all_children(self):
11521153
await asyncio.sleep(0.05)
11531154
self.log.debug("Sending SIGTERM to {pgid}")
11541155
os.killpg(pgid, SIGTERM)
1155-
if sys.platform != "win32":
1156-
await asyncio.sleep(0.05)
1157-
self.log.debug("Sending SIGKILL to {pgid}")
1158-
os.killpg(pgid, SIGKILL)
1156+
await asyncio.sleep(0.05)
1157+
self.log.debug("Sending SIGKILL to {pgid}")
1158+
os.killpg(pgid, SIGKILL)
11591159
except Exception:
11601160
self.log.exception("Exception during subprocesses termination")
11611161
return
@@ -1167,12 +1167,8 @@ async def _progressively_terminate_all_children(self):
11671167
return
11681168
self.log.debug(f"Trying to interrupt then kill subprocesses : {children}")
11691169
self._send_interupt_children()
1170-
if sys.platform != "win32":
1171-
sigs = (SIGTERM, SIGKILL)
1172-
else:
1173-
sigs = SIGTERM
11741170

1175-
for signum in sigs:
1171+
for signum in (SIGTERM, SIGKILL):
11761172
self.log.debug(
11771173
f"Will try to send {signum} ({Signals(signum)}) to subprocesses :{children}"
11781174
)

0 commit comments

Comments
 (0)