Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check if childs are still alive and shutdown instead of hanging #1177

Merged
merged 3 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,20 @@ def test_cli_incomplete_app_parameter() -> None:
assert result.exit_code == 1


def test_cli_reloader_incomplete_app_parameter(
capfd: pytest.CaptureFixture[str],
) -> None:
runner = CliRunner()

runner.invoke(cli, ["tests.test_cli", "--reload"])

captured = capfd.readouterr()

assert (
'Error loading ASGI app. Import string "tests.test_cli" '
'must be in format "<module>:<attribute>".'
) in captured.err


class App:
pass
7 changes: 7 additions & 0 deletions uvicorn/supervisors/basereload.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def run(self) -> None:
if self.should_restart():
self.restart()

if self.process.exitcode is not None:
break

self.shutdown()

def startup(self) -> None:
Expand Down Expand Up @@ -76,6 +79,10 @@ def restart(self) -> None:
def shutdown(self) -> None:
self.process.terminate()
self.process.join()

for sock in self.sockets:
sock.close()

message = "Stopping reloader process [{}]".format(str(self.pid))
color_message = "Stopping reloader process [{}]".format(
click.style(str(self.pid), fg="cyan", bold=True)
Expand Down