diff --git a/src/hypercorn/__main__.py b/src/hypercorn/__main__.py index b3dc0e80..769a5e09 100644 --- a/src/hypercorn/__main__.py +++ b/src/hypercorn/__main__.py @@ -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" @@ -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()) diff --git a/src/hypercorn/run.py b/src/hypercorn/run.py index 563822fb..05ab2391 100644 --- a/src/hypercorn/run.py +++ b/src/hypercorn/run.py @@ -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) @@ -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,