-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
- I've checked docs and closed issues for possible solutions.
- I can't find my issue in the FAQ.
Describe the bug
I am writing a script to run external programs with the subprocess
module. I want to display a status message with a spinner while the program is running. However, using simple subprocess.run
inside a status context causes the status line to be printed whenever the process prints something, which ruins the result. To illustrate it, consider a simple external program named foo
that does some "work":
#!/bin/bash
for i in $(seq 1 10); do
echo 'Working...'
sleep 1
done
echo 'Done'
Now my script looks something like this:
import subprocess
from rich.console import Console
console = Console()
with console.status("[bold green]Running..."):
subprocess.run(["./foo"])
When running this script, the status line remains on the console each time foo
prints something, which makes an ugly result:
Screencast.from.2025-10-14.13-37-30.webm
Platform
Click to expand
I am running on Linux with the Wezterm terminal.
Results of rich.diagnose
:
╭───────────────────────── <class 'rich.console.Console'> ─────────────────────────╮
│ A high level console interface. │
│ │
│ ╭──────────────────────────────────────────────────────────────────────────────╮ │
│ │ <console width=150 None> │ │
│ ╰──────────────────────────────────────────────────────────────────────────────╯ │
│ │
│ color_system = None │
│ encoding = 'utf-8' │
│ file = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'> │
│ height = 30 │
│ is_alt_screen = False │
│ is_dumb_terminal = False │
│ is_interactive = False │
│ is_jupyter = False │
│ is_terminal = False │
│ legacy_windows = False │
│ no_color = False │
│ options = ConsoleOptions( │
│ size=ConsoleDimensions(width=150, height=30), │
│ legacy_windows=False, │
│ min_width=1, │
│ max_width=150, │
│ is_terminal=False, │
│ encoding='utf-8', │
│ max_height=30, │
│ justify=None, │
│ overflow=None, │
│ no_wrap=False, │
│ highlight=None, │
│ markup=None, │
│ height=None │
│ ) │
│ quiet = False │
│ record = False │
│ safe_box = True │
│ size = ConsoleDimensions(width=150, height=30) │
│ soft_wrap = False │
│ stderr = False │
│ style = None │
│ tab_size = 8 │
│ width = 150 │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─── <class 'rich._windows.WindowsConsoleFeatures'> ────╮
│ Windows features available. │
│ │
│ ╭───────────────────────────────────────────────────╮ │
│ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │
│ ╰───────────────────────────────────────────────────╯ │
│ │
│ truecolor = False │
│ vt = False │
╰───────────────────────────────────────────────────────╯
╭────── Environment Variables ───────╮
│ { │
│ 'CLICOLOR': '1', │
│ 'COLORTERM': 'truecolor', │
│ 'COLUMNS': None, │
│ 'JPY_PARENT_PID': None, │
│ 'JUPYTER_COLUMNS': None, │
│ 'JUPYTER_LINES': None, │
│ 'LINES': None, │
│ 'NO_COLOR': None, │
│ 'TERM_PROGRAM': 'WezTerm', │
│ 'TERM': 'xterm-256color', │
│ 'TTY_COMPATIBLE': None, │
│ 'TTY_INTERACTIVE': None, │
│ 'VSCODE_VERBOSE_LOGGING': None │
│ } │
╰────────────────────────────────────╯
platform="Linux"