""" Ctrl+C stops the client at once, whatever its loop is waiting for. On Windows the client runs a selector loop (aiortc's ICE needs one), and a console event does not interrupt select(): Ctrl+C waited for the loop's next timer — half a minute in `chat --follow` between pings. """ import sys import time from console import ctrl_c, interruptible IDLE = ("import asyncio, sys\n" "from meshbay_cli.__main__ import loop_factory\n" "print('ready', flush=True)\n" "try:\n" " asyncio.run(asyncio.sleep(60), loop_factory=loop_factory())\n" "except KeyboardInterrupt:\n" " sys.exit(130)\n") def test_ctrl_c_wakes_an_idle_client_at_once(): proc = interruptible([sys.executable, "-c", IDLE], None) try: assert proc.stdout.readline().strip() == "ready", proc.stderr.read() started = time.monotonic() ctrl_c(proc) proc.wait(timeout=30) assert proc.returncode == 130, proc.stderr.read() assert time.monotonic() - started < 5 finally: if proc.poll() is None: proc.kill()