From 45a9289cbc0de79cc96aa04f3ce0dc13d55af97f Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Tue, 27 Jul 2021 09:16:14 +0200 Subject: [PATCH] fix(test): Flush stdout/stderr on http-server termination The log from http-server is lost when the process is killed. Fix this by flushing explicitly in a signal handler. --- test/http-server | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/http-server b/test/http-server index 3c40b4ee1..d96383d93 100755 --- a/test/http-server +++ b/test/http-server @@ -9,8 +9,8 @@ from functools import partial from http import HTTPStatus from http.server import HTTPServer, SimpleHTTPRequestHandler - import os +import signal import socket import sys @@ -119,6 +119,12 @@ def run(HandlerClass, ServerClass, port, bind): sys.exit(0) +def on_terminate(signum, frame): + sys.stdout.flush() + sys.stderr.flush() + sys.exit(128 + signum) + + if __name__ == "__main__": import argparse @@ -154,6 +160,9 @@ if __name__ == "__main__": os.chdir(args.directory) + signal.signal(signal.SIGINT, on_terminate) + signal.signal(signal.SIGTERM, on_terminate) + run( HandlerClass=handler_class, ServerClass=HTTPServer, -- 2.47.3