Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions gateway/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ def _read_process_cmdline(pid: int) -> Optional[str]:
if raw:
return raw.replace(b"\x00", b" ").decode("utf-8", errors="ignore").strip()

# On Windows, skip `ps` (which exists under Git Bash and would flash
# a console window) and go straight to psutil, which works correctly.
if sys.platform == "win32":
try:
import psutil # type: ignore
proc = psutil.Process(pid)
cmdline_parts = proc.cmdline()
if cmdline_parts:
return " ".join(cmdline_parts)
except Exception:
pass
return None

try:
result = subprocess.run(
["ps", "-p", str(pid), "-o", "command="],
Expand Down
13 changes: 11 additions & 2 deletions hermes_cli/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ def _get_parent_pid(pid: int) -> int | None:
pass
except Exception:
return None
# Fallback: shell out to ps (POSIX only — bare ``ps`` doesn't exist on Windows).
if not shutil.which("ps"):
# Fallback: shell out to ps (POSIX only — on Windows use psutil which
# is already tried above; Git Bash ships a ps.exe that would flash
# a console window without CREATE_NO_WINDOW).
if sys.platform == "win32" or not shutil.which("ps"):
return None
try:
result = subprocess.run(
Expand Down Expand Up @@ -4516,6 +4518,13 @@ def _atexit_hook() -> None:

success = False
try:
# On Windows, aiohttp/aiodns requires a SelectorEventLoop (Python's
# default ProactorEventLoop is incompatible). Set the policy before
# asyncio.run() creates the loop so weixin/微信 connections work.
if sys.platform == "win32":
asyncio.set_event_loop_policy(
asyncio.WindowsSelectorEventLoopPolicy() # type: ignore[attr-defined]
)
success = asyncio.run(start_gateway(replace=replace, verbosity=verbosity))
_exit_diag("asyncio.run.returned", success=success)
except KeyboardInterrupt:
Expand Down
1 change: 1 addition & 0 deletions tui_gateway/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def __init__(self, session_key: str, model: str):
bufsize=1,
cwd=os.getcwd(),
env=os.environ.copy(),
creationflags=subprocess.CREATE_NO_WINDOW if sys.platform == "win32" else 0,
)
threading.Thread(target=self._drain_stdout, daemon=True).start()
threading.Thread(target=self._drain_stderr, daemon=True).start()
Expand Down