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

Apps hang temporarily on resume from sleep #5464

Closed
Plywood9 opened this issue Jan 8, 2025 · 2 comments · Fixed by #5465
Closed

Apps hang temporarily on resume from sleep #5464

Plywood9 opened this issue Jan 8, 2025 · 2 comments · Fixed by #5465

Comments

@Plywood9
Copy link
Contributor

Plywood9 commented Jan 8, 2025

If a Textual app is suspended for some reason - typically because the device it's running on goes to sleep - then it will temporarily hang on resume from sleep and refuse to update or accept input. This is typically a minor stutter after a brief sleep; after being left overnight it can be several seconds; left for long enough it becomes minutes.

This occurs because of the loop here:

while _repeat is None or count <= _repeat:
next_timer = start + ((count + 1) * _interval)
now = _time.get_time()
if self._skip and next_timer < now:
count += 1
continue

If a timer with skip enabled has fallen behind, then it busy loops until it catches up. This is fine if it's only a little behind, but rapidly becomes expensive if it's a lot behind. This busy looping behaviour happens in, for example, the "screen_update" timer which fires every frame. An app which has been suspended racks up about five million ticks a day, enough to produce noticeable lag while the busy loop catches up.

This is easy enough to fix - just calculate the next required timer fire rather than busy looping.

Copy link

github-actions bot commented Jan 8, 2025

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

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
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant