Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support #454

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make sure all existing children will get signal send
fizyk committed May 20, 2021
commit 11d1bf61983bdbfe14d82ac74df7a1e1f822188e
9 changes: 6 additions & 3 deletions src/mirakuru/base.py
Original file line number Diff line number Diff line change
@@ -145,6 +145,7 @@ def __init__( # pylint:disable=too-many-arguments
is a good practice to set this.

"""
self.__delete = False
if isinstance(command, (list, tuple)):
self.command = " ".join((shlex.quote(c) for c in command))
"""Command that the executor runs."""
@@ -201,7 +202,6 @@ def running(self) -> bool:
:rtype: bool
"""
if self.process is None:
LOG.debug("There is no process running!")
return False
return self.process.poll() is None

@@ -300,7 +300,8 @@ def _kill_all_kids(self, sig: int) -> Set[int]:
"""
pids = processes_with_env(ENV_UUID, self._uuid)
for pid in pids:
LOG.debug("Killing process %d ...", pid)
if not self.__delete:
LOG.debug("Killing process %d ...", pid)
try:
os.kill(pid, sig)
except OSError as err:
@@ -309,7 +310,8 @@ def _kill_all_kids(self, sig: int) -> Set[int]:
pass
else:
raise
LOG.debug("Killed process %d.", pid)
if not self.__delete:
LOG.debug("Killed process %d.", pid)
return pids

def stop(
@@ -473,6 +475,7 @@ def check_timeout(self) -> bool:

def __del__(self) -> None:
"""Cleanup subprocesses created during Executor lifetime."""
self.__delete = True
try:
if self.process:
self.kill()
6 changes: 5 additions & 1 deletion src/mirakuru/kill.py
Original file line number Diff line number Diff line change
@@ -20,7 +20,11 @@ def killpg(pid: int, sig: int) -> None:
recursive=True
)
for child in children:
child.send_signal(sig)
try:
child.send_signal(sig)
except psutil.NoSuchProcess:
# Already killed
pass
psutil.wait_procs(children, timeout=30)
process.send_signal(sig)
process.wait(timeout=30)
2 changes: 0 additions & 2 deletions tests/executors/test_executor_kill.py
Original file line number Diff line number Diff line change
@@ -6,10 +6,8 @@

import errno

import os
from unittest.mock import patch

import psutil
import pytest

from mirakuru import SimpleExecutor, HTTPExecutor