-
Have you checked closed issues? https://github.com/Textualize/textual/issues?q=is%3Aissue+is%3Aclosed Yes This is a minimum example: from textual import work
from textual.app import App, ComposeResult
from textual.containers import VerticalScroll
from textual.widgets import Input, Markdown
class MarkdownExample(App):
"""Test if markdown update doesn't work when threaded"""
def compose(self) -> ComposeResult:
yield Input(placeholder="Hello World")
with VerticalScroll(id="results-container"):
yield Markdown(id="results")
async def on_input_submitted(self, message: Input.Changed) -> None:
"""A coroutine to handle a text changed message."""
if message.value:
self.do_test_thingy(message.value)
else:
# Clear the results
self.query_one("#results", Markdown).update("")
@work(exclusive=True)
def do_test_thingy(self, verse: str) -> None:
# insert sqlite operations here, doesn't seem to affect whether or not the code fails.
self.query_one("#results", Markdown).update("markdown")
if __name__ == '__main__':
app = MarkdownExample()
app.run() A bit of background to my project: I am building something that grabs values from an SQLite database, formats them, and then displays them in markdown. Originally I was using async but it was extremely slow and unresponsive due to the fact my SQLite wasn't setup to be async. So, I decided to move to threading (I noticed it towards the bottom of the Workers doc). After moving to it, processing is far faster, however I can no longer update the markdown widget. I can make other changes to it, i.e. change its visibility, but I lose access to updating it. I'm not sure if I am just laying out the workers wrong or if this is a bug! I'm not sure if there is a work around to this? I am happy to use a temporary fix whilst I am working on the project! Thanks awfully, this library has been an absolute blessing so far. Good error logs, good design, and perfect docs! ~ James It will be helpful if you run the following command and paste the results:
Textual DiagnosticsVersions
Python
Operating System
Terminal
Rich Console options
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You may want to take a look at the final paragraph in the worker docs:
In other words, the best thing for you to do here would be to either use |
Beta Was this translation helpful? Give feedback.
You may want to take a look at the final paragraph in the worker docs:
In other words, the best thing for you to do here would be to either use
call_from_thread
or to send a message up to request that the update is performed.