Debian Codegraph @

rpython/tool/killsubprocess.py

raw symbols SCIP
1 """Kill a subprocess created by subprocess.Popen().
2 The two Windows versions come from the Python cookbook.
3 """
4 import sys, os
5
6 if sys.platform != "win32":
7 import signal
8 assert hasattr(os, 'kill')
9
10 def killsubprocess(process):
11 if process.poll() is None:
12 os.kill(process.pid, signal.SIGTERM)
13
14 else:
15 # on Windows, we need either win32api or ctypes
16 try:
17 import ctypes
18 TerminateProcess = ctypes.windll.kernel32.TerminateProcess
19 except ImportError:
20 from win32api import TerminateProcess
21
22 def killsubprocess(process):
23 if process.poll() is None:
24 TerminateProcess(int(process._handle), -1)