Skip to content

Commit

Permalink
Fixing scope of variables in event handler function
Browse files Browse the repository at this point in the history
  • Loading branch information
nawaidshamim committed May 16, 2014
1 parent 53de091 commit 2c6e6c0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def on_request_success(request_type, name, response_time, response_length):
"""
Event handler that get triggered on every successful request
"""
global stats
stats["content-length"] += response_length

def on_report_to_master(client_id, data):
Expand All @@ -44,6 +45,7 @@ def on_report_to_master(client_id, data):
to be sent to the locust master. It will allow us to add our extra content-length
data to the dict that is being sent, and then we clear the local stats in the slave.
"""
global stats
data["content-length"] = stats["content-length"]
stats["content-length"] = 0

Expand All @@ -53,6 +55,7 @@ def on_slave_report(client_id, data):
from a slave. Here we just add the content-length to the master's aggregated
stats dict.
"""
global stats
stats["content-length"] += data["content-length"]

# Hook up the event listeners
Expand Down

0 comments on commit 2c6e6c0

Please sign in to comment.