Skip to content

Commit cb443a4

Browse files
seidnerjpgjones
authored andcommitted
if any of our subprocesses exits with a non-zero exit code, we should also exit with a non-zero exit code.
1 parent 80fa194 commit cb443a4

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/hypercorn/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _load_config(config_path: Optional[str]) -> Config:
2323
return Config.from_toml(config_path)
2424

2525

26-
def main(sys_args: Optional[List[str]] = None) -> None:
26+
def main(sys_args: Optional[List[str]] = None) -> int:
2727
parser = argparse.ArgumentParser()
2828
parser.add_argument(
2929
"application", help="The application to dispatch to as path.to.module:instance.path"
@@ -284,8 +284,8 @@ def _convert_verify_mode(value: str) -> ssl.VerifyMode:
284284
if len(args.server_names) > 0:
285285
config.server_names = args.server_names
286286

287-
run(config)
287+
return run(config)
288288

289289

290290
if __name__ == "__main__":
291-
main()
291+
sys.exit(main())

src/hypercorn/run.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
from .utils import load_application, wait_for_changes, write_pid_file
1616

1717

18-
def run(config: Config) -> None:
18+
def run(config: Config) -> int:
19+
exit_code = 0
20+
1921
if config.pid_path is not None:
2022
write_pid_file(config.pid_path)
2123

@@ -77,14 +79,20 @@ def shutdown(*args: Any) -> None:
7779

7880
for process in processes:
7981
process.join()
82+
if process.exitcode != 0:
83+
exit_code = process.exitcode
84+
8085
for process in processes:
8186
process.terminate()
8287

8388
for sock in sockets.secure_sockets:
8489
sock.close()
90+
8591
for sock in sockets.insecure_sockets:
8692
sock.close()
8793

94+
return exit_code
95+
8896

8997
def start_processes(
9098
config: Config,

0 commit comments

Comments
 (0)