You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thank you all so much for all your hard work on this project. I recently used this for a demonstration and was amazed by its power an elegance, and would like to give back however I can.
I encountered two small issues in the docs which that I would like to address. I will gladly issue a pull request for the bugs and changes mentioned in this issue. I felt it was courtesy to raise this issue first before issuing the pull request to ensure it would be acknowledged and accepted.
from locust import events
@events.request.add_listener
def my_request_handler(request_type, name, response_time, response_length, response,
context, exception, start_time, url, **kwargs):
if exception:
print(f"Request to {name} failed with exception {exception}")
else:
print(f"Successfully made a request to: {name})
print(f"The response was {response.text}")
The "Successfully made a request to" f-string is invalid. Running this sample code will raise an error at runtime.
Bug 2
In Running a background greenlet in
from locust import events
from locust.runners import STATE_STOPPING, STATE_STOPPED, STATE_CLEANUP, MasterRunner, LocalRunner
def checker(environment):
while not environment.runner.state in [STATE_STOPPING, STATE_STOPPED, STATE_CLEANUP]:
time.sleep(1)
if environment.runner.stats.total.fail_ratio > 0.2:
print(f"fail ratio was {environment.runner.stats.total.fail_ratio}, quitting")
environment.runner.quit()
return
@events.init.add_listener
def on_locust_init(environment, **_kwargs):
# dont run this on workers, we only care about the aggregated numbers
if isinstance(environment.runner, MasterRunner) or isinstance(environment.runner, LocalRunner):
gevent.spawn(checker, environment)
This sample code will fail in on_locust_init as it does not import gevent before using it. Running this code will raise an error at runtime.
Expected behavior
The code should be copy-and-pasteable from the docs without much modification to work. In both instances these are whole self-contained tasks and not classes.
Actual behavior
The code fails when copy-pasting into a new locust task file.
Steps to reproduce
After installing locust, copy and paste the code into a locustfile.py and run locust.
Suggested Fixes
Bug 1
Change invalid f-string to:
print(f"Successfully made a request to: {name}")
Bug 2
Import gevent, which gets installed as a dependency of locust.
import gevent
from locust import events
from locust.runners import STATE_STOPPING, STATE_STOPPED, STATE_CLEANUP, MasterRunner, LocalRunner
I again will gladly volunteer to make this change and issue a pull request.
Environment
OS: Mac OS Big Sur 11.6.8
Python version: 3.10.8
Locust version: 2.13.0
Locust command line that you ran: locust
Locust file contents (anonymized if necessary):
The text was updated successfully, but these errors were encountered:
Hi,
Thank you all so much for all your hard work on this project. I recently used this for a demonstration and was amazed by its power an elegance, and would like to give back however I can.
I encountered two small issues in the docs which that I would like to address. I will gladly issue a pull request for the bugs and changes mentioned in this issue. I felt it was courtesy to raise this issue first before issuing the pull request to ensure it would be acknowledged and accepted.
Describe the bug
https://docs.locust.io/en/stable/extending-locust.html#run-a-background-greenlet
There are two python errors in the code provided on this page, which is generated by https://github.com/locustio/locust/blob/master/docs/extending-locust.rst:
Bug 1
The first example is as follows:
The "Successfully made a request to" f-string is invalid. Running this sample code will raise an error at runtime.
Bug 2
In
Running a background greenlet
inThis sample code will fail in
on_locust_init
as it does not importgevent
before using it. Running this code will raise an error at runtime.Expected behavior
The code should be copy-and-pasteable from the docs without much modification to work. In both instances these are whole self-contained tasks and not classes.
Actual behavior
The code fails when copy-pasting into a new locust task file.
Steps to reproduce
locust
.Suggested Fixes
Bug 1
Change invalid f-string to:
Bug 2
Import gevent, which gets installed as a dependency of locust.
I again will gladly volunteer to make this change and issue a pull request.
Environment
The text was updated successfully, but these errors were encountered: