Repository navigation
Optional Django ASGI runserver integration using the embedded server #960
sipa-echo-zaoa
started this conversation in
Ideas
Replies: 1 comment
|
@sipa-echo-zaoa I think it should be a library/package on its own; I see no reason to have a |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Would an optional Django ASGI
runserverintegration, built on Granian's embedded server, be in scope for this project? Before opening a feature issue or PR, I'd like feedback on whether this belongs in Granian, a separate integration package, or a documented example.The goal is the development workflow provided by Daphne's runserver command: run the project's configured ASGI application, including custom middleware and WebSocket routing, through
python manage.py runserver, while keeping Django's development conveniences.Motivation and previous discussion
Issue #493 discussed Django debugging and Granian's production-oriented design. This proposal explores a development-only path using the existing embedded API and standard asyncio tasks, without changing the production worker architecture. The benefit would be exercising ASGI routes and Granian's HTTP/WebSocket transport locally while retaining the familiar Django workflow.
Proposed opt-in behavior
A working local implementation uses an optional Django extra and an app such as:
This is proposed configuration, not functionality currently available in a published release.
The command:
--nostaticand--insecure.--noreloadand a--noasgifallback to Django's WSGI server andWSGI_APPLICATION.django.server.Most changes are the integration, tests, fixtures, and documentation. The shared-server change is allowing
log_enabled=Noneto leave the embedding application's logging configuration intact; the current logging defaults remain unchanged.Validation so far
Local validation used Linux and CPython 3.11, with Django 4.2 and 5.2 coverage. It exercised configured ASGI middleware, async and sync views, reload after a source edit, static files, WSGI fallback, debug error pages, WebSocket echo/rejection, HTTP/2, and startup errors. The repository suite passed with 205 tests and 4 skips at the initial implementation stage; the final focused integration/embedding checks passed with 38 tests.
The installed PyCharm
pydevdbackend was exercised over its debugger protocol, using actual line breakpoints and step-over in async and sync views. These worked with--noreload, in the autoreloader child, and after a reload, using multiprocess debugging. This was backend validation, not a PyCharm GUI session or a claim of universal debugger/platform compatibility. It also does not establish that every pdb/ipdb scenario in #493 is resolved.Limits and open design questions
This would depend on the experimental embedded API and would not provide complete Daphne option parity:
--nothreadingapplies to WSGI fallback; ASGI keeps Django's usual sync adapters.SO_REUSEPORTwhere supported, so port exclusivity differs. Production worker, loop, TLS, and reload options would remain outside this command's scope.Would maintainers prefer this as a built-in optional integration, a separate package, or an example? Is the embedded API an appropriate foundation for this use case, and would the logging-configuration opt-out be acceptable? If there is interest, I can adapt the local implementation to the preferred scope before opening an issue and PR.
All reactions