Skip to content
Discussion options

You must be logged in to vote

The UI will update when the message handler finishes, which is why you are seeing this.

The solution is to make the handler a worker so it runs concurrently. And perform your long computation in a thread so it doesn't stall the event loop. Something like this:

    @on(Button.Pressed, "#LongComputationButton")
    @work
    async def action_start_long_computation(self):

          lbl = self.query_one("#LongComputationLabel")  
          lbl.content = "Please wait"
          
          await asyncio.to_thread(do_long_computation)

          lbl.content = "Computation finished"

Replies: 4 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@gabrielfougeron
Comment options

Answer selected by gabrielfougeron
Comment options

You must be logged in to vote
1 reply
@willmcgugan
Comment options

Comment options

You must be logged in to vote
2 replies
@willmcgugan
Comment options

@gabrielfougeron
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants