diff --git a/locust/main.py b/locust/main.py index 48d9dde32b..127e96659b 100644 --- a/locust/main.py +++ b/locust/main.py @@ -6,6 +6,7 @@ import socket import sys import time +import atexit import gevent @@ -411,6 +412,9 @@ def start_automatic_run(): ) ) input_listener_greenlet.link_exception(greenlet_exception_handler) + # ensure terminal is reset, even if there is an unhandled exception in locust or someone + # does something wild, like calling sys.exit() in the locustfile + atexit.register(input_listener_greenlet.kill, block=True) if options.csv_prefix: gevent.spawn(stats_csv_writer.stats_writer).link_exception(greenlet_exception_handler) @@ -472,8 +476,5 @@ def sig_term_handler(): except KeyboardInterrupt: pass except Exception: - if input_listener_greenlet is not None: - input_listener_greenlet.kill(block=False) - time.sleep(0) raise shutdown()