Skip to content

Log leak from on_unmount when run_async is used #5091

@mzebrak

Description

@mzebrak

Observed since 0.80.0, MRE works on the latest 0.82.0

When the Textual app is started via run_async, logs inside on_unmount are occasionally (often) displayed in the terminal. Occasionally (less often) there is also :

Unmount() >>> MyApp(title='MyApp', classes={'-dark-mode'}, pseudo_classes={'dark', 'focus'}) method=<MyApp.on_unmount>

being printed out.

In real app, there is also sometimes focus was removed visible from there

Running this MRE with:

MyApp().run()

instead of:

asyncio.run(MyApp().run_async())

works fine. When you close the application, nothing remains in the terminal output.

MRE:

from __future__ import annotations

import asyncio

from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Footer, Label


class MyApp(App):
    BINDINGS = [
        Binding("q", "quit", "Quit"),
    ]

    def on_load(self) -> None:
        self.log("Loaded")

    def on_mount(self) -> None:
        self.log("Mounted")

    def on_unmount(self) -> None:
        self.log("Unmounted")

    def compose(self) -> ComposeResult:
        yield Label("Press 'q' to quit.")
        yield Footer()


asyncio.run(MyApp().run_async())

terminal output:

image

This has some consequences when the app is performing startup/shutdown actions. It works OK on the startup because logs happening in on_load/on_mount are not printed to the terminal and are not visible when the app is closed. But those of the shutdown actions placed in on_unmount are.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions