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
cf5bc84872
commit
69509349bd
@ -56,6 +56,19 @@ async def log_process(cmd: List[str], logger: logging.Logger) -> asyncio.subproc
|
|||||||
return proc
|
return proc
|
||||||
|
|
||||||
|
|
||||||
|
async def log_stdout_infinite(proc: asyncio.subprocess.Process, logger: logging.Logger) -> None: # pylint: disable=no-member
|
||||||
|
empty = 0
|
||||||
|
async for line_bytes in proc.stdout: # type: ignore
|
||||||
|
line = line_bytes.decode(errors="ignore").strip()
|
||||||
|
if line:
|
||||||
|
logger.info("Console: %s", line)
|
||||||
|
empty = 0
|
||||||
|
else:
|
||||||
|
empty += 1
|
||||||
|
if empty == 100: # asyncio bug
|
||||||
|
raise RuntimeError("asyncio process: too many empty lines")
|
||||||
|
|
||||||
|
|
||||||
def ignore_sigint() -> None:
|
def ignore_sigint() -> None:
|
||||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||||
|
|
||||||
|
|||||||
@ -375,23 +375,11 @@ class Streamer: # pylint: disable=too-many-instance-attributes
|
|||||||
while True: # pylint: disable=too-many-nested-blocks
|
while True: # pylint: disable=too-many-nested-blocks
|
||||||
try:
|
try:
|
||||||
await self.__start_streamer_proc()
|
await self.__start_streamer_proc()
|
||||||
|
assert self.__streamer_proc is not None
|
||||||
empty = 0
|
await aioproc.log_stdout_infinite(self.__streamer_proc, logger)
|
||||||
async for line_bytes in self.__streamer_proc.stdout: # type: ignore
|
|
||||||
line = line_bytes.decode(errors="ignore").strip()
|
|
||||||
if line:
|
|
||||||
logger.info("Console: %s", line)
|
|
||||||
empty = 0
|
|
||||||
else:
|
|
||||||
empty += 1
|
|
||||||
if empty == 100: # asyncio bug
|
|
||||||
raise RuntimeError("Streamer/asyncio: too many empty lines")
|
|
||||||
|
|
||||||
raise RuntimeError("Streamer unexpectedly died")
|
raise RuntimeError("Streamer unexpectedly died")
|
||||||
|
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
break
|
break
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
if self.__streamer_proc:
|
if self.__streamer_proc:
|
||||||
logger.exception("Unexpected streamer error: pid=%d", self.__streamer_proc.pid)
|
logger.exception("Unexpected streamer error: pid=%d", self.__streamer_proc.pid)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user