fix(grpc): support signal shutdown on Windows - #8082
Conversation
Dinesh Yadav (dineshyadav03)
left a comment
There was a problem hiding this comment.
I read through _signal_utils.py and both call sites. The approach is sound: try add_signal_handler first, catch the NotImplementedError it actually raises on Windows' default event loop, then fall back to signal.signal() with call_soon_threadsafe to safely hop back onto the loop from the signal handler thread. Deduping signals via dict.fromkeys and restoring the previous handlers in finally are nice touches.
One concrete gap: neither new test in test_grpc_signal_utils.py is marked @pytest.mark.windows. This package's CI Windows job runs pytest -m 'windows', and that marker is the established pattern for Windows-only coverage. Without it, these tests execute on the Linux job via a monkeypatched NotImplementedError but are never collected by the actual windows-latest runner — so the fallback path stays CI-unverified on the platform it targets, despite the "2 passed on Windows" note being local-only.
Separately: is SIGBREAK (Ctrl+Break) worth including in the default signal set for stop_when_signal, or intentionally out of scope?
I'm on Windows and can sanity-check the fallback locally if useful.
Requesting changes — logic is correct, but add the windows marker so CI actually exercises the code this PR fixes.
|
Addressed the requested Windows CI coverage in
|
Why are these changes needed?
GrpcWorkerAgentRuntime.stop_when_signal()currently callsloop.add_signal_handler()unconditionally. The default Windows event loop does not implement that API, so cross-language workers fail withNotImplementedErrorinstead of waiting for shutdown. The gRPC host has the same signal-registration path.This change keeps native asyncio signal handlers on supported event loops and falls back to
signal.signal()when the event-loop API is unavailable. The fallback schedules shutdown on the owning loop withcall_soon_threadsafe, and both paths remove or restore their handlers when waiting finishes. A shared helper keeps worker and host behavior consistent.Related issue number
Closes #5760
Checks
Local validation:
pytest -q python/packages/autogen-ext/tests/test_grpc_signal_utils.py— 2 passed on WindowsAI assistance: Codex was used to inspect the failing paths, implement the fix, and run the checks above. The final diff and test behavior were reviewed before submission.