summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 5aee34d..d39eb19 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -290,6 +290,7 @@ import io
import os
import traceback
import gc
+import signal
# Exception classes used by this module.
class CalledProcessError(Exception):
@@ -317,6 +318,7 @@ if mswindows:
from win32process import CreateProcess, STARTUPINFO, \
GetExitCodeProcess, STARTF_USESTDHANDLES, \
STARTF_USESHOWWINDOW, CREATE_NEW_CONSOLE
+ from win32process import TerminateProcess
from win32event import WaitForSingleObject, INFINITE, WAIT_OBJECT_0
else:
from _subprocess import *
@@ -828,6 +830,21 @@ class Popen(object):
self.wait()
return (stdout, stderr)
+ def send_signal(self, sig):
+ """Send a signal to the process
+ """
+ if sig == signal.SIGTERM:
+ self.terminate()
+ else:
+ raise ValueError("Only SIGTERM is supported on Windows")
+
+ def terminate(self):
+ """Terminates the process
+ """
+ TerminateProcess(self._handle, 1)
+
+ kill = terminate
+
else:
#
# POSIX methods
@@ -1115,6 +1132,21 @@ class Popen(object):
self.wait()
return (stdout, stderr)
+ def send_signal(self, sig):
+ """Send a signal to the process
+ """
+ os.kill(self.pid, sig)
+
+ def terminate(self):
+ """Terminate the process with SIGTERM
+ """
+ self.send_signal(signal.SIGTERM)
+
+ def kill(self):
+ """Kill the process with SIGKILL
+ """
+ self.send_signal(signal.SIGKILL)
+
def _demo_posix():
#