Skip to content

Use asyncio.run in StatelessServer.run#561

Open
puneetdixit200 wants to merge 1 commit into
django:mainfrom
puneetdixit200:fix/stateless-server-event-loop
Open

Use asyncio.run in StatelessServer.run#561
puneetdixit200 wants to merge 1 commit into
django:mainfrom
puneetdixit200:fix/stateless-server-event-loop

Conversation

@puneetdixit200

Copy link
Copy Markdown

StatelessServer.run() currently calls asyncio.get_event_loop() before running arun(). On Python 3.14, a fresh main thread may not have a current event loop, so this raises before the server can start.

This switches the synchronous entry point to asyncio.run(self.arun()), which creates and manages the loop for this one-shot runner. I also added a regression test that patches asyncio.get_event_loop() to raise with the Python 3.14-style failure and confirms run() still reaches the handler.

Refs #559.

Tests:

  • .venv\Scripts\python -m pytest tests\test_server.py::test_run_creates_event_loop_when_none_exists -q
  • .venv\Scripts\python -m pytest tests\test_server.py -q
  • .venv\Scripts\python -m pytest -q
  • .venv\Scripts\python -m mypy .
  • git diff --check

@puneetdixit200 puneetdixit200 force-pushed the fix/stateless-server-event-loop branch from 2d669c6 to 7447fc9 Compare May 23, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant