Skip to content
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