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

[BUG] Live with RichHandler logging flickering #3182

Open
2 tasks done
xbeastx opened this issue Nov 2, 2023 · 1 comment
Open
2 tasks done

[BUG] Live with RichHandler logging flickering #3182

xbeastx opened this issue Nov 2, 2023 · 1 comment

Comments

@xbeastx
Copy link

xbeastx commented Nov 2, 2023

Describe the bug

When using Live and RichHandler sometimes it's temporary broke the things and restore back in a few milliseconds. But it could be seen.

This is video from CMD:

video.mp4

Here is 3 frames one by one:

This is even worse on Windows Terminal as it's flickering each log output when panel reach bottom of the window:

video_winterm.mp4

Looks like new log line bottoming Panel out of the terminal than it's restoring it. May be it's separated bugs...

Code example

Click to expand
import logging
import random
import string
import time
from threading import Thread

from rich.console import Group
from rich.live import Live
from rich.logging import RichHandler
from rich.panel import Panel
from rich.text import Text

logger = logging.getLogger(__name__)


def random_log():
    def random_word():
        return "".join(random.choice(string.ascii_letters) for _ in range(random.randint(3, 15)))

    while True:
        message = " ".join(random_word() for _ in range(random.randint(3, 10)))
        logger.info(message)
        time.sleep(random.uniform(0, 0.1))


def main():
    logging.basicConfig(
        level="NOTSET", format="%(message)s", datefmt="[%X]",
        handlers=[RichHandler(show_path=False, omit_repeated_times=False)]
    )

    progress_group = Group(
        Text("33333"),
        Text("2222222222"),
        Text("1111111111111"),
    )
    panel = Panel(progress_group)

    thread1 = Thread(target=random_log)
    with Live(panel, refresh_per_second=4) as _live:
        thread1.start()
        while True:
            thread1.join()


if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print("Interrupted by user")

Platform

Click to expand
>venv\Scripts\python.exe -m rich.diagnose
+---------------------- <class 'rich.console.Console'> -----------------------+
| A high level console interface.                                             |
|                                                                             |
| +-------------------------------------------------------------------------+ |
| | <console width=79 None>                                                 | |
| +-------------------------------------------------------------------------+ |
|                                                                             |
|     color_system = None                                                     |
|         encoding = 'cp1252'                                                 |
|             file = <_io.TextIOWrapper name='<stdout>' mode='w'              |
|                    encoding='cp1252'>                                       |
|           height = 25                                                       |
|    is_alt_screen = False                                                    |
| is_dumb_terminal = False                                                    |
|   is_interactive = False                                                    |
|       is_jupyter = False                                                    |
|      is_terminal = False                                                    |
|   legacy_windows = True                                                     |
|         no_color = False                                                    |
|          options = ConsoleOptions(                                          |
|                        size=ConsoleDimensions(width=79, height=25),         |
|                        legacy_windows=True,                                 |
|                        min_width=1,                                         |
|                        max_width=79,                                        |
|                        is_terminal=False,                                   |
|                        encoding='cp1252',                                   |
|                        max_height=25,                                       |
|                        justify=None,                                        |
|                        overflow=None,                                       |
|                        no_wrap=False,                                       |
|                        highlight=None,                                      |
|                        markup=None,                                         |
|                        height=None                                          |
|                    )                                                        |
|            quiet = False                                                    |
|           record = False                                                    |
|         safe_box = True                                                     |
|             size = ConsoleDimensions(width=79, height=25)                   |
|        soft_wrap = False                                                    |
|           stderr = False                                                    |
|            style = None                                                     |
|         tab_size = 8                                                        |
|            width = 79                                                       |
+-----------------------------------------------------------------------------+
+--- <class 'rich._windows.WindowsConsoleFeatures'> ----+
| Windows features available.                           |
|                                                       |
| +---------------------------------------------------+ |
| | WindowsConsoleFeatures(vt=False, truecolor=False) | |
| +---------------------------------------------------+ |
|                                                       |
| truecolor = False                                     |
|        vt = False                                     |
+-------------------------------------------------------+
+------ Environment Variables -------+
| {                                  |
|     'TERM': None,                  |
|     'COLORTERM': None,             |
|     'CLICOLOR': None,              |
|     'NO_COLOR': None,              |
|     'TERM_PROGRAM': None,          |
|     'COLUMNS': None,               |
|     'LINES': None,                 |
|     'JUPYTER_COLUMNS': None,       |
|     'JUPYTER_LINES': None,         |
|     'JPY_PARENT_PID': None,        |
|     'VSCODE_VERBOSE_LOGGING': None |
| }                                  |
+------------------------------------+
platform="Windows"

>venv\Scripts\pip.exe freeze | findstr /C:"rich"
rich==13.6.0
Copy link

github-actions bot commented Nov 2, 2023

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant