Skip to content

Commit

Permalink
Merge pull request #225 from berdario/terminate_subprocesses
Browse files Browse the repository at this point in the history
Terminate all subprocesses
  • Loading branch information
tamland committed Mar 23, 2014
2 parents d3214cc + 7095e95 commit 3a0f0ec
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/watchdog/tricks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.


import os
import signal
import subprocess
import time
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3a0f0ec

Please sign in to comment.