locustio/locust · error · Exception
User.run() is a method used internally by Locust, and you mu
Error message
User.run() is a method used internally by Locust, and you must not override it or register it as a task
What it means
Locust's User.run() method drives the internal task-execution loop. Registering a method named `run` as a task via @task would shadow it, so the @task decorator raises immediately to prevent this.
Source
Thrown at locust/user/task.py:84
@task(25)
class ForumThread(TaskSet):
@task
def get_author(self):
pass
@task
def get_created(self):
pass
"""
def decorator_func(func):
if func.__name__ in ["on_stop", "on_start"]:
logging.warning(
"You have tagged your on_stop/start function with @task. This will make the method get called both as a task AND on stop/start."
) # this is usually not what the user intended
if func.__name__ == "run":
raise Exception(
"User.run() is a method used internally by Locust, and you must not override it or register it as a task"
)
func.locust_task_weight = weight
return func
"""
Check if task was used without parentheses (not called), like this::
@task
def my_task(self)
pass
"""
if callable(weight):
func = weight
weight = 1
return decorator_func(func)
else:
return decorator_funcView on GitHub (pinned to f391a716e1)
Solutions
- Rename the method to something other than `run`
- Move custom loop logic into a normal @task method or on_start
- If overriding run intentionally, subclass and override without @task (rarely needed)
Example fix
// before
class MyUser(User):
@task
def run(self):
...
// after
class MyUser(User):
@task
def run_scenario(self):
... Defensive patterns
Strategy: validation
Validate before calling
assert not any(getattr(m, '__name__', '') == 'run' for m in vars(MyUser).values() if callable(m)), "Do not decorate run() with @task"
Prevention
- Never name task methods `run`
- Grep locustfiles for `@task` near `def run` in review
When it happens
Trigger: Applying @task (or @task(weight)) to a method named `run` on a User or TaskSet class.
Common situations: Users subclassing User and adding their own `run` logic, or renaming an existing task to `run`, then decorating it.
Related errors
- In order to use a with-block for requests, you must also pas
- Tried to set status on a request that has not yet been made.
- use start_worker
- No tag name was supplied
- No tasks defined on {self.__class__.__name__}{extra_message}
AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29).
Data as JSON: /api/errors/f1a6083146943bb8.
Report an issue: GitHub.