Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f017ac

Browse filesBrowse files
committed
Avoid making it look like kill_process works on Windows
This changes the code in Git.execute's local kill_process function, which it uses as the timed callback for kill_after_timeout, to remove code that is unnecessary because kill_process doesn't support Windows, and to avoid giving the false impression that its code could be used unmodified on Windows without serious problems. - Raise AssertionError explicitly if it is called on Windows. This is done with "raise" rather than "assert" so its behavior doesn't vary depending on "-O". - Don't pass process creation flags, because they were 0 except on Windows. - Don't fall back to SIGTERM if Python's signal module doesn't know about SIGKILL. This was specifically for Windows which has no SIGKILL. See #1756 for discussion.
1 parent f42a63b commit 2f017ac
Copy full SHA for 2f017ac

File tree

1 file changed

+7
-11
lines changed
Filter options

1 file changed

+7
-11
lines changed

‎git/cmd.py

Copy file name to clipboardExpand all lines: git/cmd.py
+7-11Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,11 +1015,9 @@ def execute(
10151015

10161016
def kill_process(pid: int) -> None:
10171017
"""Callback to kill a process."""
1018-
p = Popen(
1019-
["ps", "--ppid", str(pid)],
1020-
stdout=PIPE,
1021-
creationflags=PROC_CREATIONFLAGS,
1022-
)
1018+
if os.name == "nt":
1019+
raise AssertionError("Bug: This callback would be ineffective and unsafe on Windows, stopping.")
1020+
p = Popen(["ps", "--ppid", str(pid)], stdout=PIPE)
10231021
child_pids = []
10241022
if p.stdout is not None:
10251023
for line in p.stdout:
@@ -1028,18 +1026,16 @@ def kill_process(pid: int) -> None:
10281026
if local_pid.isdigit():
10291027
child_pids.append(int(local_pid))
10301028
try:
1031-
# Windows does not have SIGKILL, so use SIGTERM instead.
1032-
sig = getattr(signal, "SIGKILL", signal.SIGTERM)
1033-
os.kill(pid, sig)
1029+
os.kill(pid, signal.SIGKILL)
10341030
for child_pid in child_pids:
10351031
try:
1036-
os.kill(child_pid, sig)
1032+
os.kill(child_pid, signal.SIGKILL)
10371033
except OSError:
10381034
pass
10391035
kill_check.set() # Tell the main routine that the process was killed.
10401036
except OSError:
1041-
# It is possible that the process gets completed in the duration after timeout
1042-
# happens and before we try to kill the process.
1037+
# It is possible that the process gets completed in the duration after
1038+
# timeout happens and before we try to kill the process.
10431039
pass
10441040
return
10451041

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.