fix: daemon终端无日志
This commit is contained in:
@@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
import argparse
|
||||
import copy
|
||||
from dataclasses import dataclass
|
||||
from datetime import UTC, datetime
|
||||
from datetime import datetime, timezone
|
||||
from http import HTTPStatus
|
||||
from http.server import BaseHTTPRequestHandler
|
||||
import json
|
||||
@@ -16,6 +16,7 @@ import signal
|
||||
import socket
|
||||
import socketserver
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from typing import Any
|
||||
@@ -34,7 +35,7 @@ from . import (
|
||||
|
||||
|
||||
def utc_iso_now() -> str:
|
||||
return datetime.now(UTC).isoformat(timespec="seconds").replace("+00:00", "Z")
|
||||
return datetime.now(timezone.utc).isoformat(timespec="seconds").replace("+00:00", "Z")
|
||||
|
||||
|
||||
def load_omnisocket_api():
|
||||
@@ -540,6 +541,16 @@ class VideoWorkerManager:
|
||||
def start(self) -> None:
|
||||
if not self._enabled:
|
||||
return
|
||||
if not os.path.exists(self._video_cfg["binary_path"]):
|
||||
print(
|
||||
(
|
||||
"B-side video worker binary missing: "
|
||||
f"{self._video_cfg['binary_path']} "
|
||||
"(run `make b_side_video_sender` in OmniSocketGo)"
|
||||
),
|
||||
file=sys.stderr,
|
||||
flush=True,
|
||||
)
|
||||
self._thread.start()
|
||||
|
||||
def stop(self) -> None:
|
||||
@@ -650,16 +661,6 @@ class VideoWorkerManager:
|
||||
command_read_fd, command_write_fd = os.pipe()
|
||||
telemetry_read_fd, telemetry_write_fd = os.pipe()
|
||||
|
||||
def _preexec() -> None:
|
||||
os.dup2(command_read_fd, 3)
|
||||
os.dup2(telemetry_write_fd, 4)
|
||||
for fd in (command_read_fd, command_write_fd, telemetry_read_fd, telemetry_write_fd):
|
||||
if fd not in (3, 4):
|
||||
try:
|
||||
os.close(fd)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
env = dict(os.environ)
|
||||
env.update(
|
||||
{
|
||||
@@ -675,6 +676,8 @@ class VideoWorkerManager:
|
||||
"OMNI_VIDEO_OUTPUT_WIDTH": str(self._video_cfg["output_width"]),
|
||||
"OMNI_VIDEO_OUTPUT_HEIGHT": str(self._video_cfg["output_height"]),
|
||||
"OMNI_VIDEO_STATS_INTERVAL_MS": str(self._video_cfg["stats_interval_ms"]),
|
||||
"OMNI_WORKER_CONTROL_FD": str(command_read_fd),
|
||||
"OMNI_WORKER_TELEMETRY_FD": str(telemetry_write_fd),
|
||||
}
|
||||
)
|
||||
with self._lock:
|
||||
@@ -692,7 +695,6 @@ class VideoWorkerManager:
|
||||
env=env,
|
||||
close_fds=True,
|
||||
pass_fds=(command_read_fd, telemetry_write_fd),
|
||||
preexec_fn=_preexec,
|
||||
)
|
||||
except Exception as error: # pragma: no cover - runtime integration
|
||||
for fd in (command_read_fd, command_write_fd, telemetry_read_fd, telemetry_write_fd):
|
||||
@@ -1259,6 +1261,14 @@ class BSideOmniDaemon:
|
||||
daemon=True,
|
||||
)
|
||||
self._server_thread.start()
|
||||
print(
|
||||
(
|
||||
"B-side OmniDaemon ready "
|
||||
f"(state: curl --unix-socket {self.socket_path} http://localhost/v1/state)"
|
||||
),
|
||||
file=sys.stderr,
|
||||
flush=True,
|
||||
)
|
||||
self._server_thread.join()
|
||||
|
||||
def get_state(self) -> dict[str, Any]:
|
||||
@@ -1299,6 +1309,17 @@ def main(argv: list[str] | None = None) -> None:
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
app = BSideOmniDaemon(config_path=args.config_path)
|
||||
print(
|
||||
(
|
||||
"B-side OmniDaemon starting "
|
||||
f"(config={app._config['config_path']}, "
|
||||
f"socket={app._config['daemon']['socket_path']}, "
|
||||
f"ctrl_socket={app._config['daemon']['ctrl_socket_path']}, "
|
||||
f"video_enabled={app._config['video_sender']['enabled']})"
|
||||
),
|
||||
file=sys.stderr,
|
||||
flush=True,
|
||||
)
|
||||
|
||||
def _handle_signal(_signum: int, _frame: Any) -> None:
|
||||
app.stop()
|
||||
|
||||
Reference in New Issue
Block a user