summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-12-02 15:35:11 +0300
committerDevaev Maxim <[email protected]>2020-12-02 15:35:11 +0300
commit7debaa677663fa22d00df1decd932f53b97786e9 (patch)
treecaf3123cc90167699852080e4c3d82d599dc13b4
parent5bc868662a7ef2b8959a04e6678c512797ebd7be (diff)
refactoring
-rw-r--r--kvmd/aioproc.py10
-rw-r--r--kvmd/plugins/hid/_mcu/__init__.py8
-rw-r--r--kvmd/plugins/hid/bt/__init__.py8
-rw-r--r--kvmd/plugins/hid/otg/device.py7
-rw-r--r--kvmd/plugins/ugpio/ezcoo.py8
5 files changed, 14 insertions, 27 deletions
diff --git a/kvmd/aioproc.py b/kvmd/aioproc.py
index b4b84ea4..6c5fd6be 100644
--- a/kvmd/aioproc.py
+++ b/kvmd/aioproc.py
@@ -30,6 +30,8 @@ from typing import List
import setproctitle
+from .logging import get_logger
+
# =====
async def run_process(cmd: List[str], err_to_null: bool=False) -> asyncio.subprocess.Process: # pylint: disable=no-member
@@ -71,3 +73,11 @@ async def log_stdout_infinite(proc: asyncio.subprocess.Process, logger: logging.
def rename_process(suffix: str, prefix: str="kvmd") -> None:
setproctitle.setproctitle(f"{prefix}/{suffix}: {setproctitle.getproctitle()}")
+
+
+def settle(name: str, suffix: str, prefix: str="kvmd") -> logging.Logger:
+ logger = get_logger(1)
+ logger.info("Started %s pid=%d", name, os.getpid())
+ os.setpgrp()
+ rename_process(suffix, prefix)
+ return logger
diff --git a/kvmd/plugins/hid/_mcu/__init__.py b/kvmd/plugins/hid/_mcu/__init__.py
index e3234880..424f0913 100644
--- a/kvmd/plugins/hid/_mcu/__init__.py
+++ b/kvmd/plugins/hid/_mcu/__init__.py
@@ -20,7 +20,6 @@
# ========================================================================== #
-import os
import multiprocessing
import contextlib
import queue
@@ -270,12 +269,7 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
self.__events_queue.put_nowait(event)
def run(self) -> None: # pylint: disable=too-many-branches
- logger = get_logger(0)
-
- logger.info("Started HID pid=%d", os.getpid())
- os.setpgrp()
- aioproc.rename_process("hid")
-
+ logger = aioproc.settle("HID", "hid")
while not self.__stop_event.is_set():
try:
with self.__gpio:
diff --git a/kvmd/plugins/hid/bt/__init__.py b/kvmd/plugins/hid/bt/__init__.py
index 25c3b823..72830d4f 100644
--- a/kvmd/plugins/hid/bt/__init__.py
+++ b/kvmd/plugins/hid/bt/__init__.py
@@ -20,7 +20,6 @@
# ========================================================================== #
-import os
import multiprocessing
import time
@@ -194,12 +193,7 @@ class Plugin(BaseHid): # pylint: disable=too-many-instance-attributes
# =====
def __server_worker(self) -> None: # pylint: disable=too-many-branches
- logger = get_logger(0)
-
- logger.info("Started HID pid=%d", os.getpid())
- os.setpgrp()
- aioproc.rename_process("hid")
-
+ logger = aioproc.settle("HID", "hid")
while not self.__stop_event.is_set():
try:
self.__server.run()
diff --git a/kvmd/plugins/hid/otg/device.py b/kvmd/plugins/hid/otg/device.py
index 8845d9e1..73526bcf 100644
--- a/kvmd/plugins/hid/otg/device.py
+++ b/kvmd/plugins/hid/otg/device.py
@@ -78,12 +78,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
self.__stop_event = multiprocessing.Event()
def run(self) -> None:
- logger = get_logger(0)
-
- logger.info("Started HID-%s pid=%d", self.__name, os.getpid())
- os.setpgrp()
- aioproc.rename_process(f"hid-{self.__name}")
-
+ logger = aioproc.settle(f"HID-{self.__name}", f"hid-{self.__name}")
while not self.__stop_event.is_set():
try:
while not self.__stop_event.is_set():
diff --git a/kvmd/plugins/ugpio/ezcoo.py b/kvmd/plugins/ugpio/ezcoo.py
index 5c6c0e8e..f5b0bbd6 100644
--- a/kvmd/plugins/ugpio/ezcoo.py
+++ b/kvmd/plugins/ugpio/ezcoo.py
@@ -20,7 +20,6 @@
# ========================================================================== #
-import os
import re
import multiprocessing
import errno
@@ -130,12 +129,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
)
def __serial_worker(self) -> None:
- logger = get_logger(0)
-
- logger.info("Started %s pid=%d", self, os.getpid())
- os.setpgrp()
- aioproc.rename_process(f"gpio-ezcoo-{self._instance_name}")
-
+ logger = aioproc.settle(str(self), f"gpio-ezcoo-{self._instance_name}")
while not self.__stop_event.is_set():
try:
with self.__get_serial() as tty: