{"record":{"id":"f1a6083146943bb8","repo":"locustio/locust","slug":"user-run-is-a-method-used-internally-by-locust","errorCode":null,"errorMessage":"User.run() is a method used internally by Locust, and you must not override it or register it as a task","messagePattern":"User\\.run\\(\\) is a method used internally by Locust, and you must not override it or register it as a task","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"locust/user/task.py","lineNumber":84,"sourceCode":"\n            @task(25)\n            class ForumThread(TaskSet):\n                @task\n                def get_author(self):\n                    pass\n\n                @task\n                def get_created(self):\n                    pass\n    \"\"\"\n\n    def decorator_func(func):\n        if func.__name__ in [\"on_stop\", \"on_start\"]:\n            logging.warning(\n                \"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.\"\n            )  # this is usually not what the user intended\n        if func.__name__ == \"run\":\n            raise Exception(\n                \"User.run() is a method used internally by Locust, and you must not override it or register it as a task\"\n            )\n        func.locust_task_weight = weight\n        return func\n\n    \"\"\"\n    Check if task was used without parentheses (not called), like this::\n\n        @task\n        def my_task(self)\n            pass\n    \"\"\"\n    if callable(weight):\n        func = weight\n        weight = 1\n        return decorator_func(func)\n    else:\n        return decorator_func","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/user/task.py#L66-L102","documentation":"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.","triggerScenarios":"Applying @task (or @task(weight)) to a method named `run` on a User or TaskSet class.","commonSituations":"Users subclassing User and adding their own `run` logic, or renaming an existing task to `run`, then decorating it.","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)"],"exampleFix":"// before\nclass MyUser(User):\n    @task\n    def run(self):\n        ...\n// after\nclass MyUser(User):\n    @task\n    def run_scenario(self):\n        ...","handlingStrategy":"validation","validationCode":"assert not any(getattr(m, '__name__', '') == 'run' for m in vars(MyUser).values() if callable(m)), \"Do not decorate run() with @task\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never name task methods `run`","Grep locustfiles for `@task` near `def run` in review"],"tags":["python","locust","task-decorator","api-misuse"],"backgroundTag":"forbidden-method-override","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}