question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing App's sub_title fails (regression from 0.4.0)

See original GitHub issue

Since 0.5.0 (also in main), an exception is thrown when setting my App’s self.app.sub_title:

Exception in callback SimulationRunnerUI._handle_task_result(True)(<Task finishe...> result=None>)
handle: <Handle SimulationRunnerUI._handle_task_result(True)(<Task finishe...> result=None>)>
Traceback (most recent call last):
  File "/apps/hosted/spack/opt/spack/linux-rhel7-haswell/gcc-4.8.5/python-3.10.1-ek76ski4ctzhij7smku7sh3bmupopkou/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/projects/Triton/users/brechtm/triton_alpha/main/tools/chipmunk/simulations/runnerui.py", line 92, in _handle_task_result
    self.app.sub_title = "BATCH COMPLETED; EXITING"
  File "/projects/Triton/users/brechtm/triton_alpha/main/.venv/lib/python3.10/site-packages/textual/reactive.py", line 190, in __set__
    self._check_watchers(obj, name, current_value)
  File "/projects/Triton/users/brechtm/triton_alpha/main/.venv/lib/python3.10/site-packages/textual/reactive.py", line 258, in _check_watchers
    require_compute = require_compute or invoke_watcher(
  File "/projects/Triton/users/brechtm/triton_alpha/main/.venv/lib/python3.10/site-packages/textual/reactive.py", line 236, in invoke_watcher
    watch_result = watch_function(value)
  File "/projects/Triton/users/brechtm/triton_alpha/main/.venv/lib/python3.10/site-packages/textual/widgets/_header.py", line 134, in set_sub_title
    self.query_one(HeaderTitle).sub_text = sub_title
  File "/projects/Triton/users/brechtm/triton_alpha/main/.venv/lib/python3.10/site-packages/textual/dom.py", line 728, in query_one
    return query.only_one() if expect_type is None else query.only_one(expect_type)
  File "/projects/Triton/users/brechtm/triton_alpha/main/.venv/lib/python3.10/site-packages/textual/css/query.py", line 245, in only_one
    the_one = self.first(expect_type) if expect_type is not None else self.first()
  File "/projects/Triton/users/brechtm/triton_alpha/main/.venv/lib/python3.10/site-packages/textual/css/query.py", line 217, in first
    raise NoMatches(f"No nodes match {self!r}")
textual.css.query.NoMatches: No nodes match <DOMQuery Header() filter='HeaderTitle'>

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brechtmcommented, Nov 28, 2022

I was able to reproduce is a couple of times with this code, hitting ‘q’ shortly after starting the app:

import asyncio

from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, Button

class HeaderTest( App[ None ] ):

    TITLE = "This is the title"
    SUB_TITLE = "This is the sub-title"

    CSS = """
    Screen {
        align: center middle;
    }
    """
    
    BINDINGS = [
        ("q", "quit", "Quit"),
    ]

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Footer()

    def on_mount(self) -> None:
        self._task = asyncio.create_task(self._relax())
        self._task.add_done_callback(self._relax_callback)
        self.sub_title = "Starting to relax..."

    async def _relax(self):
        await asyncio.sleep(2)

    def _relax_callback(self, task: asyncio.Task) -> None:
        try:
            task.result()
        except asyncio.CancelledError:
            pass
        self.sub_title = "All relaxed now!"
        self.set_timer(2, self.action_quit)

    async def action_quit(self) -> None:
        # self._task.cancel()
        await super().action_quit()


if __name__ == "__main__":
    HeaderTest().run()

Calling cancel() on the task seems to fix the issue.

1reaction
brechtmcommented, Nov 28, 2022

I thought I would be able to reproduce it with this, but that’s not the case:

import asyncio

from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, Button

class HeaderTest( App[ None ] ):

    TITLE = "This is the title"
    SUB_TITLE = "This is the sub-title"

    CSS = """
    Screen {
        align: center middle;
    }
    """

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Footer()

    def on_mount(self) -> None:
        self._task = asyncio.create_task(self._relax())
        self._task.add_done_callback(self._relax_callback)
        self.sub_title = "Starting to relax..."

    async def _relax(self):
        await asyncio.sleep(5)

    def _relax_callback(self, task: asyncio.Task) -> None:
        self.sub_title = "All relaxed now!"


if __name__ == "__main__":
    HeaderTest().run()

The exception is raised when I quit the application. I overrode action_quit, which aborts the asyncio tasks. I’ll need to look into that further…

Read more comments on GitHub >

github_iconTop Results From Across the Web

backstage/CHANGELOG.md at master - GitHub
It is kept in the create-app template for backwards compatibility. The remove-plugin command has been removed, as it has been removed from the...
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
... Bug:114243 - "new ebuild for songanalysis-0.4.0" status:RESOLVED resolution:OBSOLETE ... Bug:271330 - "sys-apps/v86d-0.1.9 crash when changing screen on ...
Read more >
Change subtitles or languages for videos in the Apple TV app ...
To change the default subtitles language in Settings, go to Settings > Video and Audio > Audio > Subtitle Language, then choose the...
Read more >
Manage subtitle settings - Computer - YouTube Help
Captions (subtitles) are available on videos where the owner has added them, and on some videos where YouTube automatically adds them. You can...
Read more >
What's New - Oracle Linux Yum Server
tio-2.4-1.el9 - Simple TTY terminal I/O application (Update) ... rust-difflib-0.4.0-3.el9 - Port of Python's difflib library to Rust (New) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found