mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
janus runner draft
This commit is contained in:
@@ -72,7 +72,7 @@ async def log_process(
|
||||
if stdout:
|
||||
log = (logger.info if proc.returncode == 0 else logger.error)
|
||||
for line in stdout.split("\n"):
|
||||
log("Console: %s", line)
|
||||
log("=> %s", line)
|
||||
return proc
|
||||
|
||||
|
||||
@@ -81,12 +81,34 @@ async def log_stdout_infinite(proc: asyncio.subprocess.Process, logger: logging.
|
||||
async for line_bytes in proc.stdout: # type: ignore
|
||||
line = line_bytes.decode(errors="ignore").strip()
|
||||
if line:
|
||||
logger.info("Console: %s", line)
|
||||
logger.info("=> %s", line)
|
||||
empty = 0
|
||||
else:
|
||||
empty += 1
|
||||
if empty == 100: # asyncio bug
|
||||
raise RuntimeError("asyncio process: too many empty lines")
|
||||
raise RuntimeError("Asyncio process: too many empty lines")
|
||||
|
||||
|
||||
async def kill_process(proc: asyncio.subprocess.Process, wait: float, logger: logging.Logger) -> None: # pylint: disable=no-member
|
||||
if proc.returncode is None:
|
||||
try:
|
||||
proc.terminate()
|
||||
await asyncio.sleep(wait)
|
||||
if proc.returncode is None:
|
||||
try:
|
||||
proc.kill()
|
||||
except Exception:
|
||||
if proc.returncode is not None:
|
||||
raise
|
||||
await proc.wait()
|
||||
logger.info("Process killed: pid=%d; retcode=%d", proc.pid, proc.returncode)
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
except Exception:
|
||||
if proc.returncode is None:
|
||||
logger.exception("Can't kill process pid=%d", proc.pid)
|
||||
else:
|
||||
logger.info("Process killed: pid=%d; retcode=%d", proc.pid, proc.returncode)
|
||||
|
||||
|
||||
def rename_process(suffix: str, prefix: str="kvmd") -> None:
|
||||
|
||||
Reference in New Issue
Block a user