Textualize/textual · error · NoActiveWorker
There is no active worker in this task or thread.
Error message
There is no active worker in this task or thread.
What it means
NoActiveWorker raised by get_current_worker(): there is no worker associated with the current asyncio task or thread. Worker context is tracked via a contextvar/Local set only inside running worker callables, so calling this outside a worker has nothing to find.
Source
Thrown at src/textual/worker.py:77
class WorkerCancelled(WorkerError):
"""The worker was cancelled and did not complete."""
def get_current_worker() -> Worker:
"""Get the currently active worker.
Raises:
NoActiveWorker: If there is no active worker.
Returns:
A Worker instance.
"""
try:
return active_worker.get()
except LookupError:
raise NoActiveWorker(
"There is no active worker in this task or thread."
) from None
class WorkerState(enum.Enum):
"""A description of the worker's current state."""
PENDING = 1
"""Worker is initialized, but not running."""
RUNNING = 2
"""Worker is running."""
CANCELLED = 3
"""Worker is not running, and was cancelled."""
ERROR = 4
"""Worker is not running, and exited with an error."""
SUCCESS = 5
"""Worker is not running, and completed successfully."""
View on GitHub (pinned to 06dbeef4bb)
Solutions
- Only call get_current_worker() inside code run via `self.run_worker(...)` / `@work` decorated methods.
- Guard the call: try/except NoActiveWorker and fall back to non-worker behavior.
- Pass the Worker instance explicitly to helpers instead of relying on ambient context.
Example fix
# before
worker = get_current_worker()
# after
from textual.worker import NoActiveWorker
try:
worker = get_current_worker()
except NoActiveWorker:
worker = None Defensive patterns
Strategy: try-catch
Validate before calling
from textual.worker import NoActiveWorker
try:
worker = get_current_worker()
except NoActiveWorker:
worker = None Try / catch
from textual.worker import NoActiveWorker
try:
get_current_worker().check_cancelled()
except NoActiveWorker:
pass # not running as a worker Prevention
- Restrict get_current_worker() calls to code run via run_worker/@work
- Pass Worker instances explicitly to shared helpers
When it happens
Trigger: Calling `get_current_worker()` from a regular async method, a button handler, `on_mount`, or a plain thread that was not started via run_worker/run_thread with the worker machinery.
Common situations: Shared helper functions used both inside worker functions and in normal app code; calling worker APIs like `worker.check_cancelled()` or progress updates outside a worker.
Related errors
- Can not create a worker from a non-async function unless `th
- App is not running
- The `call_from_thread` method must run in a different thread
- Unsupported attempt to run a thread worker
- Request to run a non-async function as an async worker
AI-assisted analysis of Textualize/textual@06dbeef4bb (2026-08-27).
Data as JSON: /api/errors/88aa6ee5ec3930dd.
Report an issue: GitHub.