{"record":{"id":"f94a7b9efbdd2ba0","repo":"locustio/locust","slug":"you-must-define-a-wait-time-method-on-either-the","errorCode":null,"errorMessage":"You must define a wait_time method on either the {type(self.user).__name__} or {type(self).__name__} class","messagePattern":"You must define a wait_time method on either the (.+?) or (.+?) class","errorType":"exception","errorClass":"MissingWaitTimeError","httpStatus":null,"severity":"error","filePath":"locust/user/task.py","lineNumber":448,"sourceCode":"            )\n        return random.choice(self.tasks)\n\n    def wait_time(self):\n        \"\"\"\n        Method that returns the time (in seconds) between the execution of tasks.\n\n        Example::\n\n            from locust import TaskSet, between\n            class Tasks(TaskSet):\n                wait_time = between(3, 25)\n        \"\"\"\n        if self.user.wait_time:\n            return self.user.wait_time()\n        elif self.min_wait is not None and self.max_wait is not None:\n            return random.randint(self.min_wait, self.max_wait) / 1000.0\n        else:\n            raise MissingWaitTimeError(\n                \"You must define a wait_time method on either the {type(self.user).__name__} or {type(self).__name__} class\"\n            )\n\n    def wait(self):\n        \"\"\"\n        Make the running user sleep for a duration defined by the Locust.wait_time\n        function (or TaskSet.wait_time function if it's been defined).\n\n        The user can also be killed gracefully while it's sleeping, so calling this\n        method within a task makes it possible for a user to be killed mid-task, even if you've\n        set a stop_timeout. If this behaviour is not desired you should make the user wait using\n        gevent.sleep() instead.\n        \"\"\"\n        if self.user._state == LOCUST_STATE_STOPPING:\n            raise StopUser()\n        self.user._state = LOCUST_STATE_WAITING\n        self._sleep(self.wait_time())\n        if self.user._state == LOCUST_STATE_STOPPING:","sourceCodeStart":430,"sourceCodeEnd":466,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/user/task.py#L430-L466","documentation":"TaskSet.wait_time() delegates to the User's wait_time or falls back on min_wait/max_wait. If neither exists, a MissingWaitTimeError is raised telling you where to define it.","triggerScenarios":"A TaskSet runs and calls self.wait() but neither the User class nor the TaskSet defines a wait_time method (and no min_wait/max_wait set).","commonSituations":"Custom TaskSets copied without copying wait_time; Users without inherited wait_time (base User has no default).","solutions":["Define a wait_time method on the User class (e.g. between(1, 5) from locust)","Define wait_time on the TaskSet class","Set min_wait/max_wait on the TaskSet (legacy style)"],"exampleFix":"// before\nclass MyUser(User):\n    pass\n// after\nfrom locust import between\nclass MyUser(User):\n    wait_time = between(1, 5)","handlingStrategy":"validation","validationCode":"assert callable(getattr(MyUser, 'wait_time', None)) or (getattr(MyTaskSet, 'min_wait', None) is not None), \"Define wait_time on User or TaskSet\"","typeGuard":null,"tryCatchPattern":"try:\n    user.run()\nexcept MissingWaitTimeError:\n    logging.error(\"Add wait_time = between(1, 5) to your User\")","preventionTips":["Always set wait_time = between(...) on User classes","Copy wait_time when copying TaskSet templates"],"tags":["python","locust","wait-time","configuration"],"backgroundTag":"missing-wait-time","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}