Skip to content

Commit

Permalink
cleaner way to detect whether it is the second time sigint_handler is…
Browse files Browse the repository at this point in the history
… being called
  • Loading branch information
cyberw committed Nov 19, 2023
1 parent 169c63c commit c9390cf
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

version = locust.__version__

first_call = True

# Options to ignore when using a custom shape class without `use_common_options=True`
# See: https://docs.locust.io/en/stable/custom-load-shape.html#use-common-options
COMMON_OPTIONS = {
Expand Down Expand Up @@ -191,10 +189,7 @@ def is_valid_percentile(parameter):
if options.worker:
# ignore the first sigint in parent, and wait for the children to handle sigint
def sigint_handler(_signal, _frame):
global first_call
if first_call:
first_call = False
else:
if getattr(sigint_handler, "has_run"):
# if parent gets repeated sigint, we kill the children hard
for child_pid in children:
try:
Expand All @@ -205,6 +200,7 @@ def sigint_handler(_signal, _frame):
except Exception:
logging.error(traceback.format_exc())
sys.exit(1)
sigint_handler.has_run = True

signal.signal(signal.SIGINT, sigint_handler)
exit_code = 0
Expand Down

0 comments on commit c9390cf

Please sign in to comment.