mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
refactoring
This commit is contained in:
parent
5bc868662a
commit
7debaa6776
@ -30,6 +30,8 @@ from typing import List
|
|||||||
|
|
||||||
import setproctitle
|
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
|
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:
|
def rename_process(suffix: str, prefix: str="kvmd") -> None:
|
||||||
setproctitle.setproctitle(f"{prefix}/{suffix}: {setproctitle.getproctitle()}")
|
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
|
||||||
|
|||||||
@ -20,7 +20,6 @@
|
|||||||
# ========================================================================== #
|
# ========================================================================== #
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import contextlib
|
import contextlib
|
||||||
import queue
|
import queue
|
||||||
@ -270,12 +269,7 @@ class BaseMcuHid(BaseHid, multiprocessing.Process): # pylint: disable=too-many-
|
|||||||
self.__events_queue.put_nowait(event)
|
self.__events_queue.put_nowait(event)
|
||||||
|
|
||||||
def run(self) -> None: # pylint: disable=too-many-branches
|
def run(self) -> None: # pylint: disable=too-many-branches
|
||||||
logger = get_logger(0)
|
logger = aioproc.settle("HID", "hid")
|
||||||
|
|
||||||
logger.info("Started HID pid=%d", os.getpid())
|
|
||||||
os.setpgrp()
|
|
||||||
aioproc.rename_process("hid")
|
|
||||||
|
|
||||||
while not self.__stop_event.is_set():
|
while not self.__stop_event.is_set():
|
||||||
try:
|
try:
|
||||||
with self.__gpio:
|
with self.__gpio:
|
||||||
|
|||||||
@ -20,7 +20,6 @@
|
|||||||
# ========================================================================== #
|
# ========================================================================== #
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import time
|
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
|
def __server_worker(self) -> None: # pylint: disable=too-many-branches
|
||||||
logger = get_logger(0)
|
logger = aioproc.settle("HID", "hid")
|
||||||
|
|
||||||
logger.info("Started HID pid=%d", os.getpid())
|
|
||||||
os.setpgrp()
|
|
||||||
aioproc.rename_process("hid")
|
|
||||||
|
|
||||||
while not self.__stop_event.is_set():
|
while not self.__stop_event.is_set():
|
||||||
try:
|
try:
|
||||||
self.__server.run()
|
self.__server.run()
|
||||||
|
|||||||
@ -78,12 +78,7 @@ class BaseDeviceProcess(multiprocessing.Process): # pylint: disable=too-many-in
|
|||||||
self.__stop_event = multiprocessing.Event()
|
self.__stop_event = multiprocessing.Event()
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
logger = get_logger(0)
|
logger = aioproc.settle(f"HID-{self.__name}", f"hid-{self.__name}")
|
||||||
|
|
||||||
logger.info("Started HID-%s pid=%d", self.__name, os.getpid())
|
|
||||||
os.setpgrp()
|
|
||||||
aioproc.rename_process(f"hid-{self.__name}")
|
|
||||||
|
|
||||||
while not self.__stop_event.is_set():
|
while not self.__stop_event.is_set():
|
||||||
try:
|
try:
|
||||||
while not self.__stop_event.is_set():
|
while not self.__stop_event.is_set():
|
||||||
|
|||||||
@ -20,7 +20,6 @@
|
|||||||
# ========================================================================== #
|
# ========================================================================== #
|
||||||
|
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import errno
|
import errno
|
||||||
@ -130,12 +129,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __serial_worker(self) -> None:
|
def __serial_worker(self) -> None:
|
||||||
logger = get_logger(0)
|
logger = aioproc.settle(str(self), f"gpio-ezcoo-{self._instance_name}")
|
||||||
|
|
||||||
logger.info("Started %s pid=%d", self, os.getpid())
|
|
||||||
os.setpgrp()
|
|
||||||
aioproc.rename_process(f"gpio-ezcoo-{self._instance_name}")
|
|
||||||
|
|
||||||
while not self.__stop_event.is_set():
|
while not self.__stop_event.is_set():
|
||||||
try:
|
try:
|
||||||
with self.__get_serial() as tty:
|
with self.__get_serial() as tty:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user