mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
refactoring
This commit is contained in:
parent
be9ce4e4ff
commit
9cee98310d
@ -27,6 +27,8 @@ import signal
|
|||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
import setproctitle
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
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
|
||||||
@ -34,7 +36,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=preexec_ignore_sigint,
|
preexec_fn=ignore_sigint,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
@ -44,5 +46,9 @@ async def read_process(cmd: List[str], err_to_null: bool=False) -> Tuple[asyncio
|
|||||||
return (proc, stdout.decode(errors="ignore").strip())
|
return (proc, stdout.decode(errors="ignore").strip())
|
||||||
|
|
||||||
|
|
||||||
def preexec_ignore_sigint() -> None:
|
def ignore_sigint() -> None:
|
||||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||||
|
|
||||||
|
|
||||||
|
def rename_process(suffix: str, prefix: str="kvmd") -> None:
|
||||||
|
setproctitle.setproctitle(f"{prefix}/{suffix}: {setproctitle.getproctitle()}")
|
||||||
|
|||||||
@ -37,7 +37,6 @@ from typing import Any
|
|||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import aiohttp.web
|
import aiohttp.web
|
||||||
import setproctitle
|
|
||||||
|
|
||||||
from ...logging import get_logger
|
from ...logging import get_logger
|
||||||
|
|
||||||
@ -56,6 +55,7 @@ from ...validators.kvm import valid_stream_quality
|
|||||||
from ...validators.kvm import valid_stream_fps
|
from ...validators.kvm import valid_stream_fps
|
||||||
|
|
||||||
from ... import aiotools
|
from ... import aiotools
|
||||||
|
from ... import aioproc
|
||||||
|
|
||||||
from .auth import AuthManager
|
from .auth import AuthManager
|
||||||
from .info import InfoManager
|
from .info import InfoManager
|
||||||
@ -215,7 +215,7 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins
|
|||||||
|
|
||||||
def run(self, **kwargs: Any) -> None: # type: ignore # pylint: disable=arguments-differ
|
def run(self, **kwargs: Any) -> None: # type: ignore # pylint: disable=arguments-differ
|
||||||
self.__hid.start()
|
self.__hid.start()
|
||||||
setproctitle.setproctitle(f"kvmd/main: {setproctitle.getproctitle()}")
|
aioproc.rename_process("main")
|
||||||
super().run(**kwargs)
|
super().run(**kwargs)
|
||||||
|
|
||||||
async def _make_app(self) -> aiohttp.web.Application:
|
async def _make_app(self) -> aiohttp.web.Application:
|
||||||
|
|||||||
@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import select
|
import select
|
||||||
import signal
|
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import multiprocessing.queues
|
import multiprocessing.queues
|
||||||
import queue
|
import queue
|
||||||
@ -31,11 +30,10 @@ import time
|
|||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
import setproctitle
|
|
||||||
|
|
||||||
from ....logging import get_logger
|
from ....logging import get_logger
|
||||||
|
|
||||||
from .... import aiomulti
|
from .... import aiomulti
|
||||||
|
from .... import aioproc
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
@ -78,8 +76,8 @@ 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())
|
||||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
aioproc.ignore_sigint()
|
||||||
setproctitle.setproctitle(f"kvmd/hid-{self.__name}: {setproctitle.getproctitle()}")
|
aioproc.rename_process(f"hid-{self.__name}")
|
||||||
|
|
||||||
while not self.__stop_event.is_set():
|
while not self.__stop_event.is_set():
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import signal
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import multiprocessing.queues
|
import multiprocessing.queues
|
||||||
@ -35,7 +34,6 @@ from typing import Dict
|
|||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
|
|
||||||
import serial
|
import serial
|
||||||
import setproctitle
|
|
||||||
|
|
||||||
from ...logging import get_logger
|
from ...logging import get_logger
|
||||||
|
|
||||||
@ -43,6 +41,7 @@ from ...keyboard.mappings import KEYMAP
|
|||||||
|
|
||||||
from ... import aiotools
|
from ... import aiotools
|
||||||
from ... import aiomulti
|
from ... import aiomulti
|
||||||
|
from ... import aioproc
|
||||||
from ... import gpio
|
from ... import gpio
|
||||||
|
|
||||||
from ...yamlconf import Option
|
from ...yamlconf import Option
|
||||||
@ -278,8 +277,8 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
|
|||||||
logger = get_logger(0)
|
logger = get_logger(0)
|
||||||
|
|
||||||
logger.info("Started HID pid=%d", os.getpid())
|
logger.info("Started HID pid=%d", os.getpid())
|
||||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
aioproc.ignore_sigint()
|
||||||
setproctitle.setproctitle(f"kvmd/hid: {setproctitle.getproctitle()}")
|
aioproc.rename_process("hid")
|
||||||
|
|
||||||
while not self.__stop_event.is_set():
|
while not self.__stop_event.is_set():
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -45,7 +45,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.preexec_ignore_sigint,
|
preexec_fn=aioproc.ignore_sigint,
|
||||||
)
|
)
|
||||||
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user