From 7095e9550b102b2c50db5ff05525318b953a0078 Mon Sep 17 00:00:00 2001 From: Dario Bertini Date: Sat, 22 Mar 2014 22:12:15 +0100 Subject: [PATCH] Send the signal to the process group of the spawned process thus handling all its children in the same group (setsid is needed to get the process into a different group than watchdog) --- src/watchdog/tricks/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/watchdog/tricks/__init__.py b/src/watchdog/tricks/__init__.py index 203daef27..d12917802 100644 --- a/src/watchdog/tricks/__init__.py +++ b/src/watchdog/tricks/__init__.py @@ -17,6 +17,7 @@ # limitations under the License. +import os import signal import subprocess import time @@ -131,7 +132,7 @@ def __init__(self, command, patterns=None, ignore_patterns=None, kill_after=10): super(AutoRestartTrick, self).__init__( patterns, ignore_patterns, ignore_directories) - self.command = command + self.command = ['setsid'] + command self.stop_signal = stop_signal self.kill_after = kill_after self.process = None @@ -143,7 +144,7 @@ def stop(self): if self.process is None: return try: - self.process.send_signal(self.stop_signal) + os.killpg(os.getpgid(self.process.pid), self.stop_signal) except OSError: # Process is already gone pass @@ -155,7 +156,7 @@ def stop(self): time.sleep(0.25) else: try: - self.process.kill() + os.killpg(os.getpgid(self.process.pid), 9) except OSError: # Process is already gone pass