Back to Textual

How do I fix WorkerDeclarationError?

questions/worker-thread-error.question.md

8.2.5535 B
Original Source

Textual version 0.31.0 requires that you set thread=True on the @work decorator if you want to run a threaded worker.

If you want a threaded worker, you would declare it in the following way:

python
@work(thread=True)
def run_in_background():
    ...

If you don't want a threaded worker, you should make your work function async:

python
@work()
async def run_in_background():
    ...

This change was made because it was too easy to accidentally create a threaded worker, which may produce unexpected results.