Skip to content

Commit

Permalink
Merge pull request #1932 from locustio/always-restore-terminal-at-exit
Browse files Browse the repository at this point in the history
Ensure terminal is restored at exit
  • Loading branch information
cyberw authored Nov 12, 2021
2 parents ea19e9f + 62f26d8 commit a50c79a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import socket
import sys
import time
import atexit

import gevent

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit a50c79a

Please sign in to comment.