Skip to content

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

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:curses-thread-safety-note
Open

gh-154139: Document that curses is not thread-safe#154173
serhiy-storchaka wants to merge 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

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

Labels

awaiting core review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant