{"record":{"id":"3fb303ab21174cdb","repo":"Textualize/textual","slug":"unsupported-attempt-to-run-an-async-worker","errorCode":null,"errorMessage":"Unsupported attempt to run an async worker","messagePattern":"Unsupported attempt to run an async worker","errorType":"exception","errorClass":"WorkerError","httpStatus":null,"severity":"error","filePath":"src/textual/worker.py","lineNumber":344,"sourceCode":"        return await loop.run_in_executor(None, runner, self._work)\n\n    async def _run_async(self) -> ResultType:\n        \"\"\"Run an async worker.\n\n        Returns:\n            Return value of the work.\n        \"\"\"\n        if (\n            inspect.iscoroutinefunction(self._work)\n            or hasattr(self._work, \"func\")\n            and inspect.iscoroutinefunction(self._work.func)\n        ):\n            return await self._work()\n        elif inspect.isawaitable(self._work):\n            return await self._work\n        elif callable(self._work):\n            raise WorkerError(\"Request to run a non-async function as an async worker\")\n        raise WorkerError(\"Unsupported attempt to run an async worker\")\n\n    async def run(self) -> ResultType:\n        \"\"\"Run the work.\n\n        Implement this method in a subclass, or pass a callable to the constructor.\n\n        Returns:\n            Return value of the work.\n        \"\"\"\n        return await (\n            self._run_threaded() if self._thread_worker else self._run_async()\n        )\n\n    async def _run(self, app: App) -> None:\n        \"\"\"Run the worker.\n\n        Args:\n            app: App instance.","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/worker.py#L326-L362","documentation":"WorkerError from Worker._run_async: the work item matches none of the supported async kinds (partial of coroutine function, awaitable, callable). It is effectively unreachable for well-typed inputs and signals an internal/unsupported work object in async mode.","triggerScenarios":"Passing an object that is not awaitable and not callable to an async worker — e.g. a data value or an object whose __call__ raises on inspection edge cases; almost always from direct Worker construction with invalid work.","commonSituations":"Dynamic/generic code that forwards arbitrary objects into run_worker; subclassing Worker and setting _work incorrectly.","solutions":["Ensure the work passed to run_worker is an async function, a partial thereof, or an awaitable.","Use a plain function with thread=True for sync work.","Type-check before scheduling: `if not (inspect.isawaitable(w) or callable(w)): raise ValueError`."],"exampleFix":"# before\nself.run_worker(some_object)\n# after\nself.run_worker(asyncio.to_thread(sync_fn))  # awaitable, runs blocking fn","handlingStrategy":"validation","validationCode":"import inspect\nif not (inspect.isawaitable(w) or inspect.iscoroutinefunction(w) or callable(w)):\n    raise ValueError('unsupported work item')","typeGuard":"def is_async_work(w) -> bool:\n    import inspect\n    return inspect.isawaitable(w) or callable(w)","tryCatchPattern":"from textual.worker import WorkerError\ntry:\n    await worker.run()\nexcept WorkerError as e:\n    raise RuntimeError(f'bad worker config: {e}') from e","preventionTips":["Only pass async functions, partials thereof, or awaitables to async workers","Type-check the work argument in wrappers around run_worker"],"tags":["worker","async","unsupported-operation","textual"],"backgroundTag":"worker-misconfiguration","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}