Skip to content

Fix Process.terminal() returning None for PTYs opened after first call - #2838

Open
SAY-5 wants to merge 3 commits into
giampaolo:masterfrom
SAY-5:fix-terminal-stale-cache-2830
Open

Fix Process.terminal() returning None for PTYs opened after first call#2838
SAY-5 wants to merge 3 commits into
giampaolo:masterfrom
SAY-5:fix-terminal-stale-cache-2830

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 26, 2026

Copy link
Copy Markdown

Summary

Description

get_terminal_map() is decorated with @functools.lru_cache and is never invalidated. In a long-running process that first calls terminal() (or process_iter(['terminal'])) before any PTYs exist, the cache is built empty. All PTYs created afterwards are invisible to subsequent calls since the cached empty dict is returned and the lookup returns None.

On a cache miss the terminal device number is genuinely absent from the cached map. Clearing the cache and rebuilding once picks up any /dev/pts/* entries that have appeared since the initial call.

@SAY-5

SAY-5 commented May 26, 2026

Copy link
Copy Markdown
Author

Note: the linter CI failure is pre-existing on master (failing since 2026-05-21 15:01:49 +0200) and not caused by this PR. All 28 ruff PLW0717 errors come from files not touched by this change.

SAY-5 added 3 commits July 27, 2026 14:29
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5
SAY-5 force-pushed the fix-terminal-stale-cache-2830 branch from 3dcf57f to 9e3f140 Compare July 27, 2026 21:29
@giampaolo giampaolo added bug type linux platform : Linux specific bsd platform : the BSDs as a family, none of them named macos platform : macOS specific labels Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bsd platform : the BSDs as a family, none of them named bug type linux platform : Linux specific macos platform : macOS specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Linux] Process.terminal() returns None for PTYs allocated after the first call (get_terminal_map cache never refreshes)

2 participants