Skip to content

gh-154139: Document that curses is not thread-safe - #154173

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:curses-thread-safety-note
Aug 13, 2026
Merged

gh-154139: Document that curses is not thread-safe#154173
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:curses-thread-safety-note

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 19, 2026

Copy link
Copy Markdown
Member

Documents the thread-safety limitation reported in #154139.

_curses releases the GIL around the blocking and refresh calls (getch, refresh, …), so with a non-reentrant curses — the default ncurses build on many systems — two threads can race on the shared global screen state and crash the interpreter. Whether curses is usable from multiple threads depends on the library and how it was built, so this is a documentation gap rather than a missing lock in CPython.

The note points to serializing the calls or wrapping them in window.use() / screen.use(), which lock only when the library is built with reentrant support.

Whether curses is thread-safe depends on the library and how it was built.
The blocking and refresh methods release the GIL, so with a non-reentrant
curses, unsynchronized use from several threads can crash.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33655502 | 📁 Comparing f14a57c against main (f252132)

  🔍 Preview build  

1 file changed
± library/curses.html

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes and removed needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Aug 13, 2026
@serhiy-storchaka
serhiy-storchaka merged commit 1ed6b78 into python:main Aug 13, 2026
48 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Aug 13, 2026
@serhiy-storchaka
serhiy-storchaka deleted the curses-thread-safety-note branch August 13, 2026 10:15
@bedevere-app

bedevere-app Bot commented Aug 13, 2026

Copy link
Copy Markdown

GH-155690 is a backport of this pull request to the 3.15 branch.

@bedevere-app

bedevere-app Bot commented Aug 13, 2026

Copy link
Copy Markdown

GH-155691 is a backport of this pull request to the 3.14 branch.

@bedevere-app

bedevere-app Bot commented Aug 13, 2026

Copy link
Copy Markdown

GH-155692 is a backport of this pull request to the 3.13 branch.

serhiy-storchaka added a commit that referenced this pull request Aug 13, 2026
…GH-155692)

Whether curses is thread-safe depends on the library and how it was built.
The blocking and refresh methods release the GIL, so with a non-reentrant
curses, unsynchronized use from several threads can crash.

The reference to window.use() and screen.use() is omitted: they were added
in 3.16.

(cherry picked from commit 1ed6b78)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
serhiy-storchaka added a commit that referenced this pull request Aug 13, 2026
…GH-155691)

Whether curses is thread-safe depends on the library and how it was built.
The blocking and refresh methods release the GIL, so with a non-reentrant
curses, unsynchronized use from several threads can crash.

The reference to window.use() and screen.use() is omitted: they were added
in 3.16.

(cherry picked from commit 1ed6b78)

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
mbeijen pushed a commit to mbeijen/cpython that referenced this pull request Aug 14, 2026
…4173)

Whether curses is thread-safe depends on the library and how it was built.
The blocking and refresh methods release the GIL, so with a non-reentrant
curses, unsynchronized use from several threads can crash.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant