Skip to content

Commit

Permalink
Compat for SIGQUIT
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk committed May 6, 2021
1 parent 8e8025b commit ccce7a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/mirakuru/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@
# Windows does not have SIGKILL, fall back to SIGTERM.
SIGKILL = getattr(signal, "SIGKILL", signal.SIGTERM)

# Windows does not have SIGQUIT, fall back to SIGTERM.
SIGQUIT = getattr(signal, "SIGQUIT", signal.SIGTERM)


__all__ = ("SIGKILL",)
10 changes: 5 additions & 5 deletions tests/executors/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""Test basic executor functionality."""
import gc
import shlex
import signal
from subprocess import check_output
import uuid
from unittest import mock
Expand All @@ -11,6 +10,7 @@

from mirakuru import Executor
from mirakuru.base import SimpleExecutor
from mirakuru.compat import SIGQUIT
from mirakuru.exceptions import ProcessExitedWithError, TimeoutExpired

from tests import SAMPLE_DAEMON_PATH, ps_aux
Expand Down Expand Up @@ -44,7 +44,7 @@ def test_command(command):

def test_custom_signal_stop():
"""Start process and shuts it down using signal SIGQUIT."""
executor = SimpleExecutor(SLEEP_300, sig_stop=signal.SIGQUIT)
executor = SimpleExecutor(SLEEP_300, sig_stop=SIGQUIT)
executor.start()
assert executor.running() is True
executor.stop()
Expand All @@ -56,7 +56,7 @@ def test_stop_custom_signal_stop():
executor = SimpleExecutor(SLEEP_300)
executor.start()
assert executor.running() is True
executor.stop(sig=signal.SIGQUIT)
executor.stop(sig=SIGQUIT)
assert executor.running() is False


Expand All @@ -65,14 +65,14 @@ def test_stop_custom_exit_signal_stop():
executor = SimpleExecutor("false", shell=True)
executor.start()
# false exits instant, so there should not be a process to stop
retry(lambda: executor.stop(sig=signal.SIGQUIT, exp_sig=3))
retry(lambda: executor.stop(sig=SIGQUIT, exp_sig=3))
assert executor.running() is False


def test_stop_custom_exit_signal_context():
"""Start process and expect custom exit signal in context manager."""
with SimpleExecutor("false", exp_sig=3, shell=True) as executor:
executor.stop(sig=signal.SIGQUIT)
executor.stop(sig=SIGQUIT)
assert executor.running() is False


Expand Down
9 changes: 3 additions & 6 deletions tests/executors/test_executor_kill.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# mypy: no-strict-optional
"""Tests that check various kill behaviours."""
import signal
import time
import sys

import errno

import os
from unittest.mock import patch

import psutil
import pytest

from mirakuru import SimpleExecutor, HTTPExecutor
from mirakuru.compat import SIGKILL
from mirakuru.compat import SIGKILL, SIGQUIT
from mirakuru.exceptions import ProcessFinishedWithError
from mirakuru.kill import killpg

Expand All @@ -24,7 +21,7 @@

def test_custom_signal_kill():
"""Start process and shuts it down using signal SIGQUIT."""
executor = SimpleExecutor(SLEEP_300, sig_kill=signal.SIGQUIT)
executor = SimpleExecutor(SLEEP_300, sig_kill=SIGQUIT)
executor.start()
assert executor.running() is True
executor.kill()
Expand All @@ -36,7 +33,7 @@ def test_kill_custom_signal_kill():
executor = SimpleExecutor(SLEEP_300)
executor.start()
assert executor.running() is True
executor.kill(sig=signal.SIGQUIT)
executor.kill(sig=SIGQUIT)
assert executor.running() is False


Expand Down

0 comments on commit ccce7a2

Please sign in to comment.