-
Notifications
You must be signed in to change notification settings - Fork 814
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
Awaiting the mount of many widgets may break the app #4022
Comments
Seems to be stack related. If you increase the stack size it can handle 500 widgets. Simpler MRE: from textual.app import App
from textual.widgets import Label
# import sys
# sys.setrecursionlimit(10**6)
class LabelApp(App[None]):
async def on_mount(self):
for _ in range(500):
await self.mount(Label(";)"))
if __name__ == "__main__":
LabelApp().run() Suggest we try to get a failed stack trace, and seem if we can make it less deep. I'm also wondering if there is something significant about mounting widgets from the mount handler, which feels like an odd thing to do, but should be possible. Update: it also only occurs if you await the mounts. |
It looks like this was introduced in https://github.com/Textualize/textual/pull/3065/files. Specifically the change from
|
Don't forget to star the repository! Follow @textualizeio for Textual updates. |
If you mount many widgets in succession with
mount
and await their mount, your app may break.Even if using
mount_all
works just fine.In the example below, if I use
mount_all
to mount 500 labels, Textual doesn't even bat an eye.If I use
mount
on a loop 500 times, the app breaks and doesn't even clean up properly.The exact number may depend on your machine.
(Seems like it may be the fact that
AwaitMount
creates a task whenever it is awaited, so that's 500 tasks formount
vs a single task formount_all
.)Screen.Recording.2024-01-15.at.11.53.28.mov
Code:
The text was updated successfully, but these errors were encountered: