Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log slow message processing #4895

Closed
willmcgugan opened this issue Aug 18, 2024 · 3 comments · Fixed by #4905
Closed

Log slow message processing #4895

willmcgugan opened this issue Aug 18, 2024 · 3 comments · Fixed by #4905
Assignees
Labels
good first issue Good for newcomers

Comments

@willmcgugan
Copy link
Collaborator

If processing messages take longer than a fraction of a second, it can cause the UI to freeze.

This is usually the result blocking operations or cpu intensive work in a message handler. The solution is typically to do the work in a worker, but devs may not know to do that.

Given its a gotcha, I think Textual can do a little more to help.

I think what we should do is time how long a message has taken to process. If it is longer than, say 500ms, it should log a warning.

This should only be enabled in debug mode. The maximum time should be set in an environment variable.

I suspect, the best place to do this would be https://github.com/Textualize/textual/blob/main/src/textual/message_pump.py#L637

Requirements:

  • Display warning for message handers that take a long time
  • Enable in debug mode
  • Add env var to set the time that produces a warning
  • Should not add to much cpu work to message processing

Bonus points

Strictly following the above, would not produce a warning until the handler returns. If it takes 30 seconds, the dev would not see anything.

It would be great if long running message handlers produce a warning even before the handler returns. This would be a little trickier to implement. And it should be done in a way that doesn't slow down non-debug runs.

@willmcgugan willmcgugan added the good first issue Good for newcomers label Aug 18, 2024
@Zimzozaur
Copy link
Contributor

Let me give this a shot 🙂

@willmcgugan
Copy link
Collaborator Author

Assigned to you. Let us know how it goes.

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants