diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-10-15 17:42:30 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-10-15 17:45:41 +0200 |
| commit | 41d03f0a35a95daa7d54e7f29ab924776bedf6e4 (patch) | |
| tree | 2e631013746f913413b9811562b9c9a4734a0e41 /packages/meshbay-cli/src/meshbay_cli/__main__.py | |
| parent | 39cac2878de059992cb09a1ccf09b6bcece99fae (diff) | |
| download | meshbay-41d03f0a35a95daa7d54e7f29ab924776bedf6e4.tar.gz | |
fix(cli): make the command-line client work on Windows
Its suite had only run on Linux. On Windows, against a real hub and node and
from the installed meshbay-cli.exe:
- secrets.enc was written in text mode (os.open without O_BINARY): every 0x0A
of the ciphertext became CR LF and the saved session "does not open with
its key" on the next run.
- isatty() is true for NUL, so a script run with `< NUL` or by the Task
Scheduler was asked questions instead of told to pass --yes;
output.terminal() checks for a real console.
- Ctrl+C waited for the selector loop's next timer, up to half a minute in
`chat --follow`; the loop now points the signal wakeup at its self-pipe,
as the proactor does.
- Right-click copy and paste raised: asyncio cannot start a process on the
selector loop; the clipboard tool runs in a thread.
- Tab completion of remote paths ran on the default (proactor) loop, which
never opens a node, and wrote in the locale encoding; the PowerShell script
now reads it as UTF-8.
- `get -R` into a folder past MAX_PATH died with a traceback; get, put, the
resume file and the interactive mode use the extended form at each disk
call, as the node does.
- `groups` showed a SQLite hub's naive UTC time as local time.
The opt-in end-to-end suite now runs on Windows (16 tests: Chrome found under
Program Files and started with the real environment, VLC as the player, Ctrl+C
through a console of its own, PowerShell 5.1 completion of an accented name).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-cli/src/meshbay_cli/__main__.py')
| -rw-r--r-- | packages/meshbay-cli/src/meshbay_cli/__main__.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/packages/meshbay-cli/src/meshbay_cli/__main__.py b/packages/meshbay-cli/src/meshbay_cli/__main__.py index f5cee22..597e2fe 100644 --- a/packages/meshbay-cli/src/meshbay_cli/__main__.py +++ b/packages/meshbay-cli/src/meshbay_cli/__main__.py @@ -8,7 +8,9 @@ import argparse import asyncio import logging import os +import signal import sys +import threading from . import __version__ from .commands import ( @@ -113,15 +115,35 @@ async def _run(args: argparse.Namespace) -> int: await ctx.aclose() +class _WindowsSelectorLoop(asyncio.SelectorEventLoop): + """ + A selector loop that Ctrl+C wakes. Windows' select() is not interrupted by + a console event, and unlike the proactor (`windows_events.ProactorEventLoop. + run_forever`) this loop never points the signal wakeup at its self-pipe: Ctrl+C + waited for the next timer, which in `chat --follow` or `stream` can be half + a minute away (measured: 29 s on a loop whose next timer was 30 s off). + """ + + def run_forever(self): + if threading.current_thread() is not threading.main_thread(): + return super().run_forever() # signals reach the main thread only + old = signal.set_wakeup_fd(self._csock.fileno()) + try: + super().run_forever() + finally: + signal.set_wakeup_fd(old) + + def loop_factory(): """aiortc's ICE needs a selector loop: Windows' default proactor never completes a DataChannel handshake.""" - return asyncio.SelectorEventLoop if sys.platform == "win32" else None + return _WindowsSelectorLoop if sys.platform == "win32" else None def main(argv: list[str] | None = None) -> int: argv = sys.argv[1:] if argv is None else argv if argv[:1] == ["__complete"]: + _utf8_output() # what the completion scripts read from .complete import main as complete return complete(argv[1:]) if not argv and os.environ.get("MESHBAY_CLI_SELFTEST") == "1": |