textual: Crash opening and closing dialog really fast
I’ve been stress-testing my app and I think I found a concurrency issue in the library:
<╭────────────────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────────────────────────────────────────────────────────────╮
│ /home/arcivanov/.pyenv/versions/app/lib/python3.12/site-packages/textual/widget.py:3734 in _compose │
│ │
│ 3731 │ │ │ self.app._handle_exception(error) ╭────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ 3732 │ │ else: │ self = TradeDialog() │ │
│ 3733 │ │ │ self._extend_compose(widgets) │ widgets = [ToastRack(id='textual-toastrack'), Tooltip(id='textual-tooltip'), TradeWidget()] │ │
│ ❱ 3734 │ │ │ await self.mount_composed_widgets(widgets) ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ 3735 │ │
│ 3736 │ async def mount_composed_widgets(self, widgets: list[Widget]) -> None: │
│ 3737 │ │ """Called by Textual to mount widgets after compose. │
│ │
│ /home/arcivanov/.pyenv/versions/app/lib/python3.12/site-packages/textual/widget.py:3747 in mount_composed_widgets │
│ │
│ 3744 │ │ │ widgets: A list of child widgets. ╭────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ 3745 │ │ """ │ self = TradeDialog() │ │
│ 3746 │ │ if widgets: │ widgets = [ToastRack(id='textual-toastrack'), Tooltip(id='textual-tooltip'), TradeWidget()] │ │
│ ❱ 3747 │ │ │ await self.mount_all(widgets) ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ 3748 │ │
│ 3749 │ def _extend_compose(self, widgets: list[Widget]) -> None: │
│ 3750 │ │ """Hook to extend composed widgets. │
│ │
│ /home/arcivanov/.pyenv/versions/app/lib/python3.12/site-packages/textual/widget.py:1016 in mount_all │
│ │
│ 1013 │ │ """ ╭────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ 1014 │ │ if self.app._exit: │ after = None │ │
│ 1015 │ │ │ return AwaitMount(self, []) │ before = None │ │
│ ❱ 1016 │ │ await_mount = self.mount(*widgets, before=before, after=after) │ self = TradeDialog() │ │
│ 1017 │ │ return await_mount │ widgets = [ToastRack(id='textual-toastrack'), Tooltip(id='textual-tooltip'), TradeWidget()] │ │
│ 1018 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ 1019 │ if TYPE_CHECKING: │
│ │
│ /home/arcivanov/.pyenv/versions/app/lib/python3.12/site-packages/textual/widget.py:947 in mount │
│ │
│ 944 │ │ if self._closing: ╭────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ 945 │ │ │ return AwaitMount(self, []) │ after = None │ │
│ 946 │ │ if not self.is_attached: │ before = None │ │
│ ❱ 947 │ │ │ raise MountError(f"Can't mount widget(s) before {self!r} is mounted") │ self = TradeDialog() │ │
│ 948 │ │ # Check for duplicate IDs in the incoming widgets │ widgets = (ToastRack(id='textual-toastrack'), Tooltip(id='textual-tooltip'), TradeWidget()) │ │
│ 949 │ │ ids_to_mount = [ ╰─────────────────────────────────────────────────────────────────────────────────────────────╯ │
│ 950 │ │ │ widget_id for widget in widgets if (widget_id := widget.id) is not None │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
MountError: Can't mount widget(s) before TradeDialog() is mounted
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 25 (8 by maintainers)
Yep, I removed the textual completely, installed it from the tree and can no longer bang out any of the problem.
For what it’s worth, after pulling the latest changes on my fork of Textual, I can’t reproduce the issue using the simplified MRE in https://github.com/Textualize/textual/issues/4668#issuecomment-2186463224 when mashing the <kbd>o</kbd> and <kbd>Esc</kbd> keys.
The MRE can be even further simplified. Recomposition and dynamic structure is irrelevant. The issue pops up the more eagerly the more controls are on the modal screen. The last crash occurred with just two
o-ESCsequences.