stop signals propagation in 3.9

This commit is contained in:
Devaev Maxim
2020-12-02 15:07:08 +03:00
parent 2b064a3bee
commit 5bc868662a
6 changed files with 8 additions and 13 deletions

View File

@@ -20,9 +20,9 @@
# ========================================================================== # # ========================================================================== #
import os
import asyncio import asyncio
import asyncio.subprocess import asyncio.subprocess
import signal
import logging import logging
from typing import Tuple from typing import Tuple
@@ -37,7 +37,7 @@ async def run_process(cmd: List[str], err_to_null: bool=False) -> asyncio.subpro
*cmd, *cmd,
stdout=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,
stderr=(asyncio.subprocess.DEVNULL if err_to_null else asyncio.subprocess.STDOUT), stderr=(asyncio.subprocess.DEVNULL if err_to_null else asyncio.subprocess.STDOUT),
preexec_fn=ignore_sigint, preexec_fn=os.setpgrp,
)) ))
@@ -69,9 +69,5 @@ async def log_stdout_infinite(proc: asyncio.subprocess.Process, logger: logging.
raise RuntimeError("asyncio process: too many empty lines") raise RuntimeError("asyncio process: too many empty lines")
def ignore_sigint() -> None:
signal.signal(signal.SIGINT, signal.SIG_IGN)
def rename_process(suffix: str, prefix: str="kvmd") -> None: def rename_process(suffix: str, prefix: str="kvmd") -> None:
setproctitle.setproctitle(f"{prefix}/{suffix}: {setproctitle.getproctitle()}") setproctitle.setproctitle(f"{prefix}/{suffix}: {setproctitle.getproctitle()}")

View File

@@ -273,7 +273,7 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
logger = get_logger(0) logger = get_logger(0)
logger.info("Started HID pid=%d", os.getpid()) logger.info("Started HID pid=%d", os.getpid())
aioproc.ignore_sigint() os.setpgrp()
aioproc.rename_process("hid") aioproc.rename_process("hid")
while not self.__stop_event.is_set(): while not self.__stop_event.is_set():

View File

@@ -197,7 +197,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
logger = get_logger(0) logger = get_logger(0)
logger.info("Started HID pid=%d", os.getpid()) logger.info("Started HID pid=%d", os.getpid())
aioproc.ignore_sigint() os.setpgrp()
aioproc.rename_process("hid") aioproc.rename_process("hid")
while not self.__stop_event.is_set(): while not self.__stop_event.is_set():

View File

@@ -81,7 +81,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
logger = get_logger(0) logger = get_logger(0)
logger.info("Started HID-%s pid=%d", self.__name, os.getpid()) logger.info("Started HID-%s pid=%d", self.__name, os.getpid())
aioproc.ignore_sigint() os.setpgrp()
aioproc.rename_process(f"hid-{self.__name}") aioproc.rename_process(f"hid-{self.__name}")
while not self.__stop_event.is_set(): while not self.__stop_event.is_set():

View File

@@ -133,7 +133,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
logger = get_logger(0) logger = get_logger(0)
logger.info("Started %s pid=%d", self, os.getpid()) logger.info("Started %s pid=%d", self, os.getpid())
aioproc.ignore_sigint() os.setpgrp()
aioproc.rename_process(f"gpio-ezcoo-{self._instance_name}") aioproc.rename_process(f"gpio-ezcoo-{self._instance_name}")
while not self.__stop_event.is_set(): while not self.__stop_event.is_set():

View File

@@ -20,6 +20,7 @@
# ========================================================================== # # ========================================================================== #
import os
import asyncio import asyncio
import pwd import pwd
@@ -29,8 +30,6 @@ from typing import Optional
import pytest import pytest
from kvmd import aioproc
from . import get_configured_auth_service from . import get_configured_auth_service
@@ -45,7 +44,7 @@ async def _run_process(cmd: str, input: Optional[str]=None) -> None: # pylint:
proc = await asyncio.create_subprocess_exec( proc = await asyncio.create_subprocess_exec(
*cmd.split(" "), *cmd.split(" "),
stdin=(asyncio.subprocess.PIPE if input is not None else None), stdin=(asyncio.subprocess.PIPE if input is not None else None),
preexec_fn=aioproc.ignore_sigint, preexec_fn=os.setpgrp,
) )
await proc.communicate(input.encode() if input is not None else None) await proc.communicate(input.encode() if input is not None else None)
assert proc.returncode == 0 assert proc.returncode == 0