Skip to content

Commit

Permalink
Merge pull request #1415 from Zooce/init-event-documentation
Browse files Browse the repository at this point in the history
Add simple documentation with use case for init event
  • Loading branch information
cyberw authored Jun 6, 2020
2 parents 165d877 + e601df8 commit f226d78
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/writing-a-locustfile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,25 @@ events. You can set up listeners for these events at the module level of your lo
When running Locust distributed the ``test_start`` and ``test_stop`` events will only be fired in the master node.

init event
==========

The ``init`` event is triggered at the beginning of each Locust process. This is especially useful in distributed mode
where each worker process (not each user) needs a chance to do some initialization. For example, let's say you have some
global state that all users spawned from this process will need:

.. code-block:: python
from locust import events
from locust.runners import MasterRunner
@events.init.add_listener
def on_locust_init(environment, **kwargs):
if isinstance(environment.runner, MasterRunner):
print("I'm on master node")
else:
print("I'm on a worker or standalone node")
Making HTTP requests
=====================
Expand Down

0 comments on commit f226d78

Please sign in to comment.