Replies: 1 comment 2 replies
-
Hey @iscas-zac, I couldn't understand 100% what you're trying to do or demonstrate with your generator For example, if I create the pane and add it in a function that is “called from thread”, like you can see below, there are no errors: from textual import work
from textual.app import App, ComposeResult
from textual.widgets import TabbedContent, TabPane, Input, Static
class TestApp(App):
def compose(self) -> ComposeResult:
yield TabbedContent()
yield Input()
async def on_mount(self):
self.async_caller()
@work(thread=True, exit_on_error=False)
async def async_caller(self):
a = self.call_from_thread(self.yielder)
next(a)
def yielder(self):
tc = self.query_one(TabbedContent)
def add_the_pane():
tc.add_pane(TabPane("1234", Static(), id="_1234"))
self.call_from_thread(add_the_pane)
yield "the work is done now. close it"
if __name__ == "__main__":
TestApp().run() Now, depending on your final objective, it may be possible to remove some of these indirections that my code has (the worker that calls the generator that calls another function with |
Beta Was this translation helpful? Give feedback.
-
The issue
When I'm working with yielders, the app prints a lot of traceback after I close it.
The sample code is like this, which I run with
textual run --dev main.py
with main.py containing just aapp.run()
:After I Ctrl-C it, it exits and prints
Triggering conditions
The issue involves some patterns.
add_pane()
should sit in a yielder.on_mount()
function, it won't trigger.TabPane
must contain a child widget (the child can also be added afterwards instead of as a parameter, both will trigger).My
textual diagnose
outputTextual Diagnostics
Versions
Python
Operating System
Terminal
Rich Console options
Afterwords
I'm not sure if I use it right. I want the computation-heavy yielder task both to give some feedback when running and to run in a different thread, so I write codes with workers and yield statements. The problem doesn't affect my experience when it runs, so I guess I'll be OK if this isn't fixed.
Beta Was this translation helpful? Give feedback.
All reactions