Repository navigation
feat: add run_sync() with event loop selection and a uvloop extra - #20
Merged
Merged
Conversation
The Host never creates a loop — servicewright.run() is a coroutine and the documented entry point was asyncio.run(run(service, settings)) — so there was no sanctioned way to run on uvloop: uvicorn's own loop= selection never applies (the entrypoints drive uvicorn inside the Host's loop), uvloop only arrived as a transitive dependency of uvicorn[standard] and nothing switched to it, and the obvious incantation, an event loop policy, is deprecated in Python 3.14. run_sync(service, settings, *, loop="auto") is the blocking twin of run(): it creates the loop through asyncio.run(..., loop_factory=...) — "asyncio", "uvloop" (an ImportError naming the extra when missing) or "auto" (uvloop when installed) — installs the OS signal handlers as run() does, and lets whatever the Host raises propagate. event_loop_factory() is exported for embedding. uvloop is resolved lazily by dotted path like the observability backends, and joins the import-linter's stdlib-only list for the kernel. A uvloop extra is added (and to [all]); the readiness log line now carries event_loop=<module.Class>, so which loop a service runs on is in the logs. Closes #19
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Closes #19 — a sanctioned way to run the Host on uvloop.
Problem. The Host never creates a loop (
run()is a coroutine; the documented entry point wasasyncio.run(run(service, settings))), uvicorn's ownloop=selection never applies because the entrypoints drive uvicorn inside the Host's loop, uvloop only arrived as a transitive dependency ofuvicorn[standard]and nothing switched to it, and the obvious incantation — an event loop policy — is deprecated in Python 3.14.Design.
run_sync(service, settings, *, loop="auto"), module-level and asService.run_sync(): the blocking twin ofrun(). It creates the loop throughasyncio.run(..., loop_factory=...), installs the OS signal handlers asrun()does when nostopis supplied, and lets whatever the Host raises propagate, so the exit code keeps its meaning.loopis"asyncio","uvloop"(anImportErrornaming the extra when it is missing) or"auto"(uvloop when installed — uvicorn's convention for the same knob).event_loop_factory(loop)is exported for embedding.uvloopjoins the import-linter's "core is stdlib-only" forbidden list — the kernel's zero-dependency import stays enforced.uvloopextra (uvloop>=0.21), included inalland in the test group.event_loop=<module.Class>(uvloop.Loop,asyncio.unix_events._UnixSelectorEventLoop).run_sync(service, settings); the lifecycle page gets an "Event loop" section; the installation page and the README list the extra. The other blueprints keepasyncio.run(service.run(settings)), which stays correct.uv.lock: refreshed for the new extra (it also picks up the package's own version, which the lock still recorded as 0.1.0).Rejected (in the issue): a
loopfield onAppSpec/settings (a process concern, not a description of the service), installing a policy (deprecated, process-global), documentinguvloop.run()only.Type of change
Checklist
run_syncrunning the service on uvloop / on asyncio (a probe entrypoint records the running loop's implementation),Service.run_sync, a raising entrypoint propagating after cleanup, the readiness log field; the file cannot even import againstmaster(cannot import name 'run_sync')make checkpasses locally (ruff+mypy+lint-imports, 3 contracts kept withuvloopnow forbidden in core)CHANGELOG.md— generated by release-please from thefeat:commitVerification
make check: cleanpytest -m unit --cov-fail-under=90: 648 passed, 10 skipped, coverage 93.17%zensical build --clean: no issuesRelated issues
Closes #19