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
File "/usr/local/lib/python3.6/site-packages/locust/core.py", line 358, in run
self.schedule_task(self.get_next_task())
File "/usr/local/lib/python3.6/site-packages/locust/core.py", line 419, in get_next_task
return random.choice(self.tasks)
File "/usr/local/lib/python3.6/random.py", line 258, in choice
return seq[i]
KeyError: 38
This is occurring because self.tasks is a dictionary, not a list. Instead it should use: random.choice(self.tasks.keys()) if self.tasks is a dict.
This isn't quite correct. tasks on a TaskSet class might be defined as a callable:int dict, but this is then parsed into a sequance in the TaskSetMeta class:
if "tasks" in classDict and classDict["tasks"] is not None:
tasks = classDict["tasks"]
if isinstance(tasks, dict):
tasks = six.iteritems(tasks)
for task in tasks:
if isinstance(task, tuple):
task, count = task
for i in xrange(0, count):
new_tasks.append(task)
else:
new_tasks.append(task)
I suspect your issue is more related to the way in which you're defining your callables. Can you post / send me the actual code that is raising this error (not just a snippet)
Description of issue / feature request
The docs state you specify weights for callables: https://docs.locust.io/en/stable/writing-a-locustfile.html#tasks-attribute, by the tasks attribute being a dictionary. However you get a KeyError.
Expected behavior
A task should be selected.
Actual behavior
There is a KeyError when selecting a task:
This is occurring because self.tasks is a dictionary, not a list. Instead it should use:
random.choice(self.tasks.keys())
if self.tasks is a dict.Environment settings (for bug reports)
Steps to reproduce (for bug reports)
The text was updated successfully, but these errors were encountered: