Skip to content

Commit fcc93c8

Browse files
committed
Reload workers on SIGHUP
This can be quite useful to take into account code changes, configuration changes, or new certificates to load.
1 parent fbcc9c3 commit fcc93c8

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/hypercorn/run.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ def run(config: Config) -> int:
5555
active = True
5656
shutdown_event = ctx.Event()
5757

58+
def reload(*args: Any) -> None:
59+
shutdown_event.set()
60+
for process in processes:
61+
process.join()
62+
shutdown_event.clear()
63+
5864
def shutdown(*args: Any) -> None:
5965
nonlocal active
6066
shutdown_event.set()
@@ -73,16 +79,16 @@ def shutdown(*args: Any) -> None:
7379
if hasattr(signal, signal_name):
7480
signal.signal(getattr(signal, signal_name), shutdown)
7581

82+
if hasattr(signal, "SIGHUP"):
83+
signal.signal(signal.SIGHUP, reload)
84+
7685
if config.use_reloader:
7786
files = files_to_watch()
7887
while True:
7988
finished = wait((process.sentinel for process in processes), timeout=1)
8089
updated = check_for_updates(files)
8190
if updated:
82-
shutdown_event.set()
83-
for process in processes:
84-
process.join()
85-
shutdown_event.clear()
91+
reload()
8692
break
8793
if len(finished) > 0:
8894
break

0 commit comments

Comments
 (0)