Skip to content

Do reload on receiving SIGHUP #304

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 9 additions & 4 deletions src/hypercorn/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def shutdown(*args: Any) -> None:
shutdown_event.set()
active = False

def reload(*args: Any) -> None:
nonlocal shutdown_event
shutdown_event.set()
for process in processes:
process.join()
shutdown_event.clear()

processes: List[BaseProcess] = []
while active:
# Ignore SIGINT before creating the processes, so that they
Expand All @@ -72,17 +79,15 @@ def shutdown(*args: Any) -> None:
for signal_name in {"SIGINT", "SIGTERM", "SIGBREAK"}:
if hasattr(signal, signal_name):
signal.signal(getattr(signal, signal_name), shutdown)
signal.signal(signal.SIGHUP, reload)

if config.use_reloader:
files = files_to_watch()
while True:
finished = wait((process.sentinel for process in processes), timeout=1)
updated = check_for_updates(files)
if updated:
shutdown_event.set()
for process in processes:
process.join()
shutdown_event.clear()
reload()
break
if len(finished) > 0:
break
Expand Down