Skip to content

Commit

Permalink
if any of our subprocesses exits with a non-zero exit code, we should…
Browse files Browse the repository at this point in the history
… also exit with a non-zero exit code.
  • Loading branch information
seidnerj authored and pgjones committed Dec 27, 2023
1 parent 80fa194 commit cb443a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/hypercorn/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _load_config(config_path: Optional[str]) -> Config:
return Config.from_toml(config_path)


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

run(config)
return run(config)


if __name__ == "__main__":
main()
sys.exit(main())
10 changes: 9 additions & 1 deletion src/hypercorn/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
from .utils import load_application, wait_for_changes, write_pid_file


def run(config: Config) -> None:
def run(config: Config) -> int:
exit_code = 0

if config.pid_path is not None:
write_pid_file(config.pid_path)

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

for process in processes:
process.join()
if process.exitcode != 0:
exit_code = process.exitcode

for process in processes:
process.terminate()

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

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

return exit_code


def start_processes(
config: Config,
Expand Down

0 comments on commit cb443a4

Please sign in to comment.