{"record":{"id":"7cc0184c5d416ee6","repo":"locustio/locust","slug":"use-start-worker","errorCode":null,"errorMessage":"use start_worker","messagePattern":"use start_worker","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"locust/runners.py","lineNumber":1291,"sourceCode":"            self.client.send(Message(\"exception\", {\"msg\": str(exception), \"traceback\": formatted_tb}, self.client_id))\n\n        self.environment.events.user_error.add_listener(on_user_error)\n\n    def spawning_complete(self, user_count):\n        assert user_count == sum(self.user_classes_count.values())\n        self.client.send(\n            Message(\n                \"spawning_complete\",\n                {\"user_classes_count\": self.user_classes_count, \"user_count\": self.user_count},\n                self.client_id,\n            )\n        )\n        self.worker_state = STATE_RUNNING\n\n    def start(\n        self, user_count: int, spawn_rate: float, wait: bool = False, user_classes: list[type[User]] | None = None\n    ) -> None:\n        raise NotImplementedError(\"use start_worker\")\n\n    def start_worker(self, user_classes_count: dict[str, int], **kwargs) -> None:\n        \"\"\"\n        Start running a load test as a worker\n\n        :param user_classes_count: Users to run\n        \"\"\"\n        self.target_user_classes_count = user_classes_count\n        self.target_user_count = sum(user_classes_count.values())\n\n        for user_class in self.user_classes:\n            if self.environment.host:\n                user_class.host = self.environment.host\n\n        user_classes_spawn_count: dict[str, int] = {}\n        user_classes_stop_count: dict[str, int] = {}\n\n        for user_class_name, user_class_count in user_classes_count.items():","sourceCodeStart":1273,"sourceCodeEnd":1309,"githubUrl":"https://github.com/locustio/locust/blob/f391a716e12c2c712e80b5835e877b7933397453/locust/runners.py#L1273-L1309","documentation":"WorkerRunner does not support the generic UserRunner.start() API used by the master/local runners. Calling start() on a worker-mode runner raises this explicit NotImplementedError to point the developer at the worker-specific start_worker() method, which takes a dict of user class names to counts instead of a user count and spawn rate.","triggerScenarios":"Calling runner.start(user_count, spawn_rate) on a WorkerRunner instance, e.g. after launching locust with --worker and programmatically invoking the runner API intended for standalone/master mode.","commonSituations":"Scripts that reuse the same start() call for both local and worker mode; custom orchestration code that connects a worker node and tries to drive it like a master; refactoring shared runner code without checking runner type.","solutions":["Call runner.start_worker({'MyUserClass': count}) instead of runner.start(...)","Check the runner type (isinstance(runner, WorkerRunner)) before invoking start()","If driving workers programmatically, let the master distribute user counts rather than starting tasks directly on the worker"],"exampleFix":"// before\nrunner.start(100, 10)\n// after\nif isinstance(runner, WorkerRunner):\n    runner.start_worker({\"MyHttpUser\": 100})\nelse:\n    runner.start(100, 10)","handlingStrategy":"validation","validationCode":"if isinstance(runner, WorkerRunner):\n    raise RuntimeError(\"Use start_worker() on worker runners\")","typeGuard":"from locust.runners import WorkerRunner\ndef is_worker(runner):\n    return isinstance(runner, WorkerRunner)","tryCatchPattern":null,"preventionTips":["Branch on runner type before invoking lifecycle methods","Keep master and worker bootstrap code in separate functions","Check locust docs for mode-specific runner APIs"],"tags":["locust","distributed","worker","api-misuse"],"backgroundTag":"unsupported-method-on-runner-mode","analyzedSha":"f391a716e12c2c712e80b5835e877b7933397453","analyzedAt":"2026-08-29T00:36:13.872Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}