Skip to content

Commit b045306

Browse files
committed
faq entry
1 parent 5a306e9 commit b045306

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

FAQ.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [How can I select and copy text in a Textual app?](#how-can-i-select-and-copy-text-in-a-textual-app)
88
- [How can I set a translucent app background?](#how-can-i-set-a-translucent-app-background)
99
- [How do I center a widget in a screen?](#how-do-i-center-a-widget-in-a-screen)
10+
- [How do I fixed WorkerDeclarationError?](#how-do-i-fixed-workerdeclarationerror)
1011
- [How do I pass arguments to an app?](#how-do-i-pass-arguments-to-an-app)
1112
- [Why do some key combinations never make it to my app?](#why-do-some-key-combinations-never-make-it-to-my-app)
1213
- [Why doesn't Textual look good on macOS?](#why-doesn't-textual-look-good-on-macos)
@@ -144,6 +145,29 @@ if __name__ == "__main__":
144145
ButtonApp().run()
145146
```
146147

148+
<a name="how-do-i-fixed-workerdeclarationerror"></a>
149+
## How do I fixed WorkerDeclarationError?
150+
151+
Textual version 0.31.0 requires that you set `thread=True` on the `@work` decorator if you want to run a threaded worker.
152+
153+
If you want a threaded worker, you would declare it in the following way:
154+
155+
```python
156+
@work(thread=True)
157+
def run_in_background():
158+
...
159+
```
160+
161+
If you *don't* want a worker, you should make your work function `async`:
162+
163+
```python
164+
@work():
165+
async def run_in_background():
166+
...
167+
```
168+
169+
This change was made because it was easy to accidentally created a threaded worker, which may produce unexpected results.
170+
147171
<a name="how-do-i-pass-arguments-to-an-app"></a>
148172
## How do I pass arguments to an app?
149173

0 commit comments

Comments
 (0)