locustio/locust · error · MissingWaitTimeError

You must define a wait_time method on either the {type(self.

Error message

You must define a wait_time method on either the {type(self.user).__name__} or {type(self).__name__} class

What it means

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.

Source

Thrown at locust/user/task.py:448

            )
        return random.choice(self.tasks)

    def wait_time(self):
        """
        Method that returns the time (in seconds) between the execution of tasks.

        Example::

            from locust import TaskSet, between
            class Tasks(TaskSet):
                wait_time = between(3, 25)
        """
        if self.user.wait_time:
            return self.user.wait_time()
        elif self.min_wait is not None and self.max_wait is not None:
            return random.randint(self.min_wait, self.max_wait) / 1000.0
        else:
            raise MissingWaitTimeError(
                "You must define a wait_time method on either the {type(self.user).__name__} or {type(self).__name__} class"
            )

    def wait(self):
        """
        Make the running user sleep for a duration defined by the Locust.wait_time
        function (or TaskSet.wait_time function if it's been defined).

        The user can also be killed gracefully while it's sleeping, so calling this
        method within a task makes it possible for a user to be killed mid-task, even if you've
        set a stop_timeout. If this behaviour is not desired you should make the user wait using
        gevent.sleep() instead.
        """
        if self.user._state == LOCUST_STATE_STOPPING:
            raise StopUser()
        self.user._state = LOCUST_STATE_WAITING
        self._sleep(self.wait_time())
        if self.user._state == LOCUST_STATE_STOPPING:

View on GitHub (pinned to f391a716e1)

Solutions

  1. Define a wait_time method on the User class (e.g. between(1, 5) from locust)
  2. Define wait_time on the TaskSet class
  3. Set min_wait/max_wait on the TaskSet (legacy style)

Example fix

// before
class MyUser(User):
    pass
// after
from locust import between
class MyUser(User):
    wait_time = between(1, 5)
Defensive patterns

Strategy: validation

Validate before calling

assert callable(getattr(MyUser, 'wait_time', None)) or (getattr(MyTaskSet, 'min_wait', None) is not None), "Define wait_time on User or TaskSet"

Try / catch

try:
    user.run()
except MissingWaitTimeError:
    logging.error("Add wait_time = between(1, 5) to your User")

Prevention

When it happens

Trigger: 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).

Common situations: Custom TaskSets copied without copying wait_time; Users without inherited wait_time (base User has no default).

Related errors


AI-assisted analysis of locustio/locust@f391a716e1 (2026-08-29). Data as JSON: /api/errors/f94a7b9efbdd2ba0. Report an issue: GitHub.