Skip to content

Exit runserver when Daphne startup aborts#583

Open
lin-hongkuan wants to merge 2 commits into
django:mainfrom
lin-hongkuan:codex/runserver-abort-on-listen-failure
Open

Exit runserver when Daphne startup aborts#583
lin-hongkuan wants to merge 2 commits into
django:mainfrom
lin-hongkuan:codex/runserver-abort-on-listen-failure

Conversation

@lin-hongkuan

@lin-hongkuan lin-hongkuan commented Jun 24, 2026

Copy link
Copy Markdown

Summary

  • make the Django runserver command check Server.abort_start after Server.run() returns
  • raise CommandError when Daphne aborts during startup, matching the standalone CLI behavior of exiting non-zero
  • add a focused runserver startup test that simulates an abort from the server

Fixes #577

Tests

  • python -m pytest tests\test_runserver_startup.py tests\test_cli.py -q
  • python -m pytest -q tests --ignore=tests/test_packaging.py
  • python -m black --check daphne\management\commands\runserver.py tests\test_runserver_startup.py
  • python -m flake8 daphne\management\commands\runserver.py tests\test_runserver_startup.py
  • git diff --check

Note: python -m pytest -q fails in my local editable-install environment only at tests/test_packaging.py::test_fd_endpoint_plugin_installed, because the Twisted plugin file is not present under the selected site-packages path. The runtime tests pass with that packaging-only test excluded.

@lin-hongkuan lin-hongkuan force-pushed the codex/runserver-abort-on-listen-failure branch 2 times, most recently from c034688 to 9b37c14 Compare June 24, 2026 17:37
@lin-hongkuan lin-hongkuan force-pushed the codex/runserver-abort-on-listen-failure branch from cf2209a to ece3e67 Compare June 25, 2026 03:28
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.

When using daphne, if some process is already listening on our preferred port, runserver does not exit with a failure code.

1 participant