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

Possible dev tools and threads issue #4060

Closed
willmcgugan opened this issue Jan 22, 2024 · 3 comments
Closed

Possible dev tools and threads issue #4060

willmcgugan opened this issue Jan 22, 2024 · 3 comments

Comments

@willmcgugan
Copy link
Collaborator

willmcgugan commented Jan 22, 2024

While debugging Tailless, I often find the app gets stuck, but only when running devtools.

I suspect there is some interaction with threads and devtools here.

If any one picks this up, please try first to reproduce with an MRE. I may be wrong.

Update: I suspect what I'm seeing is just because I am writing very large print statements. It may not be a threading issue per se.

@tconbeer
Copy link
Contributor

I've noticed this when moving a lot of data through workers and messages. Kind of related to #2588 because the default output to console can end up calling repr on and then printing some very large objects, which noticeably slows things down.

This app runs in 0.4 s without the console (python app.py), but doesn't even finish the first paint before hanging for >5 minutes when run with textual run --dev app.py.

from __future__ import annotations
from textual._path import CSSPathType
from textual.app import App, CSSPathType, ComposeResult
from textual.driver import Driver
from textual.widgets import Static
import time
from textual import work, on
from textual.message import Message


class SlowConsole(App):
    class Result(Message):
        def __init__(self, len: int) -> None:
            self.len = len
            super().__init__()

    def __init__(
        self,
        driver_class: type[Driver] | None = None,
        css_path: CSSPathType | None = None,
        watch_css: bool = False,
    ):
        self.data = [(i, "one", "two", "three", "four") for i in range(1_000_000)]
        self.start = time.monotonic()
        super().__init__(driver_class, css_path, watch_css)

    def compose(self) -> ComposeResult:
        self.static = Static("working")
        yield self.static

    def on_mount(self) -> None:
        self.check_data(self.data)

    @work(thread=True)
    def check_data(self, data: list) -> None:
        self.post_message(self.Result(len(data)))

    @on(Result)
    def update_static(self, message: Result) -> None:
        self.static.update(f"{message.len}  {time.monotonic() - self.start}")


SlowConsole().run()

@darrenburns
Copy link
Member

We've decided to park this for now after thinking about alternative approaches. We couldn't think of anything that we can do that wouldn't massively interfere with how useful the devtools are in general.

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

No branches or pull requests

3 participants