RuntimeError: There is no current event loop in thread 'asyncio_0'. happens on python 3.9 #3857
-
from textual import work
from textual.app import App, ComposeResult, events
from textual.containers import *
from textual.widgets import *
class ScriptApp(App):
CSS = """
.unselected {
display: none;
}
.unselected.visible {
display: block;
}
"""
def compose(self) -> ComposeResult:
PROJECT_KEY = [
("LPS", "LPS"),
("LRQA", "LRQA"),
("LRAC", "LRAC"),
("COMMERCE", "COMMERCE"),
]
yield Header()
yield Label("Project Key:", id="project-key-label-2")
yield Select(PROJECT_KEY, id="project-key-2")
yield Label("Summary:", id="summary-label", classes="unselected")
yield Input(id="summary", classes="unselected")
yield Static()
yield Button("Submit", id="button-7")
yield Footer()
@work(exclusive=True, thread=True)
def create_issue(self) -> None:
self.query_one("#button-7").disabled = True
self.query_one("#summary").value = ""
self.query_one("#project-key-2").clear()
self.query_one("#button-7").disabled = False
self.query_one("#summary").remove_class("visible")
self.query_one("#summary-label").remove_class("visible")
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "button-7":
self.create_issue()
def on_select_changed(self, event: Select.Changed) -> None:
self.query_one("#summary").set_class(event.value != Select.BLANK, "visible")
self.query_one("#summary-label").set_class(
event.value != Select.BLANK, "visible"
)
app = ScriptApp()
if __name__ == "__main__":
app.run() |
Beta Was this translation helpful? Give feedback.
Answered by
willmcgugan
Dec 12, 2023
Replies: 1 comment 1 reply
-
Threaded workers need a little more care. You won't be able to update the DOM directly, but you can send messages or use See this section in the docs for details... https://textual.textualize.io/guide/workers/#thread-workers |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Tim-Cao
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Threaded workers need a little more care. You won't be able to update the DOM directly, but you can send messages or use
App.call_from_thread
.See this section in the docs for details... https://textual.textualize.io/guide/workers/#thread-workers