Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyboardInterrupt does not gracefully exit custom load shape #1910

Closed
ghost opened this issue Oct 21, 2021 · 8 comments
Closed

KeyboardInterrupt does not gracefully exit custom load shape #1910

ghost opened this issue Oct 21, 2021 · 8 comments
Labels

Comments

@ghost
Copy link

ghost commented Oct 21, 2021

Describe the bug

KeyboardInterrupt does not gracefully exit custom load shape.

Expected behavior

A report should be generated after Ctrl-C, like with a normal test case.

Actual behavior

The program crashes:

[2021-10-21 10:07:23,218] user-vm/INFO/locust.runners: Shape worker starting
[2021-10-21 10:07:23,218] user-vm/INFO/locust.runners: Shape test updating to 10 users at 10.00 spawn rate
[2021-10-21 10:07:23,218] user-vm/INFO/locust.runners: Ramping to 10 users at a rate of 10.00 per second
[2021-10-21 10:07:23,219] user-vm/INFO/locust.runners: All users spawned: {"WebsiteUser": 10} (10 total users)
^CKeyboardInterrupt
2021-10-21T08:07:24Z
Traceback (most recent call last):
  File "/home/user/.local/bin/locust", line 8, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.7/site-packages/locust/main.py", line 383, in main
    start_automatic_run()
  File "/home/user/.local/lib/python3.7/site-packages/locust/main.py", line 370, in start_automatic_run
    environment.runner.shape_greenlet.join()
  File "src/gevent/greenlet.py", line 831, in gevent._gevent_cgreenlet.Greenlet.join
  File "src/gevent/greenlet.py", line 857, in gevent._gevent_cgreenlet.Greenlet.join
  File "src/gevent/greenlet.py", line 846, in gevent._gevent_cgreenlet.Greenlet.join
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
KeyboardInterrupt

Steps to reproduce

Use this example from this very repo, launched as locust --headless -f step_load.py --host https://localhost:

Environment

@ghost ghost added the bug label Oct 21, 2021
@cyberw
Copy link
Collaborator

cyberw commented Oct 21, 2021

@max-rocket-internet Do you have a minute to look at this?

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it label Dec 21, 2021
@github-actions
Copy link

github-actions bot commented Jan 1, 2022

This issue was closed because it has been stalled for 10 days with no activity. This does not necessarily mean that the issue is bad, but it most likely means that nobody is willing to take the time to fix it. If you have found Locust useful, then consider contributing a fix yourself!

@github-actions github-actions bot closed this as completed Jan 1, 2022
@JevonCowell
Copy link
Contributor

JevonCowell commented Jul 30, 2023

I believe this issue still persists (using 2.14.2). From the error trace we see that it fails in
environment.runner.shape_greenlet.join()

It's dirty, but we could catch it like this to let it end gracefully:

# start the test
            if environment.shape_class:
                if options.run_time:
                    sys.stderr.write("It makes no sense to combine --run-time and LoadShapes. Bailing out.\n")
                    sys.exit(1)
                try:
                    logger.info("Modified Locust Main is running")
                    environment.runner.start_shape()
                    environment.runner.shape_greenlet.join()
                except KeyboardInterrupt:
                    logging.info("Exiting due to CTRL+C interruption")
                finally:
                    stop_and_optionally_quit()

Thoughts? Locust's inability to gracefully exit means @events.test_stop.add_listener doesn't work.

@cyberw
Copy link
Collaborator

cyberw commented Jul 30, 2023

LGTM, PR very welcome. PR with unit test even more so :)

I'd skip the "modified locust main is running" logging though (unclear what that even means)

@cyberw cyberw reopened this Jul 30, 2023
@cyberw cyberw removed the stale Issue had no activity. Might still be worth fixing, but dont expect someone else to fix it label Jul 30, 2023
@JevonCowell
Copy link
Contributor

#2375

@cyberw cyberw closed this as completed in 8e8a341 Jul 31, 2023
@JevonCowell
Copy link
Contributor

Sorry to reopen this issue, I was wondering what the release cadence of locust was or something I have to do on my end to get the next version released with these changes

@cyberw
Copy link
Collaborator

cyberw commented Aug 3, 2023

There’s no particular cadence and the current master version has a feature that I might not want to release after all :) but I can probably squeeze it in this weekend. But you can always use the latest PR merge using pip install --pre locust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants