NoActiveAppError when DataTable add_column is invoked from worker thread #3927
-
When I am wondering if this as designed or not? It is understandable that interacting with the application UI elements is inherently not thread safe. I assumed however that creating new widgets in another worker thread is acceptable. Could someone please clarify on this one? The use-case I am trying to use it with is following - I am trying to construct a big table and keep application responsive in the mean time, then as soon as table is ready I was going to
PS. Thank you for very nice project, it is a pleasure to experiment with! from textual import work
from textual.app import App
from textual.widgets import Static, DataTable
class MyApp(App):
def compose(self):
self.start_work()
yield Static('HELLO')
@work(exclusive=True, thread=True)
def start_work(self):
dt = DataTable()
dt.add_column('foo')
self.call_from_thread(
lambda: self.mount(Static('DONE!'))
)
if __name__ == '__main__':
app = MyApp()
app.run() Here is traceback part:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You're trying to manipulate a widget (the |
Beta Was this translation helpful? Give feedback.
-
Thank you for a quick answer @davep! That's interesting, the same approach works when no worker threads are involved, right? If you have any useful links that would allow to comprehend this matter more I would highly appreciate you sharing it! Do you happen to have any other suggestions for the use-case I've described (creating a big DataTable while keeping application responsive)? |
Beta Was this translation helpful? Give feedback.
I should also have mentioned that you were also sort of violating the rule of doing UI-based things in a non-thread-safe way; so your code will run if you write it like this:
(note adding the column in a th…