fix: Handle signal registration outside the main thread#218
Merged
igalshilman merged 4 commits intoJul 23, 2026
Conversation
brightsparc
marked this pull request as ready for review
July 23, 2026 02:43
brightsparc
marked this pull request as draft
July 23, 2026 02:43
brightsparc
marked this pull request as ready for review
July 23, 2026 03:08
igalshilman
approved these changes
Jul 23, 2026
igalshilman
left a comment
Contributor
There was a problem hiding this comment.
Looks good!, thank you @brightsparc !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ValueErrorwhen an event loop rejectsadd_signal_handler()Root cause
Restate installs a SIGTERM handler while serving the ASGI application. The existing code handles
NotImplementedErrorandRuntimeError, which covers unsupported platforms and asyncio's behavior outside the main thread.uvloop raises
ValueErrorinstead whenadd_signal_handler()is called outside the main thread. Granian runs each ASGI worker on its own thread, so Restate requests failed with:This was observed with Granian, uvloop, and free-threaded CPython 3.14.6. Switching Granian to the asyncio loop avoided the exception, but lost the desired uvloop runtime.
Impact
The additional exception handling lets Restate applications run under Granian worker threads with uvloop, including free-threaded Python deployments. Signal registration remains best-effort, matching the existing behavior for asyncio and unsupported platforms.
No Granian-specific or uvloop-specific runtime patch is introduced.
Validation
restatedev/sdk-python:maingit diff --checkpassedGET /restate/healthwhen signal registration raisesValueErrorcargo metadataat zero CPU due to unrelated long-running Cargo jobs on the development machine; upstream CI should execute the focused test