From a29a65b74717a467d4c32ec208eec67768f865af Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 13 Aug 2026 13:15:29 +0300 Subject: [PATCH] [3.13] gh-154139: Document that curses is not thread-safe (GH-154173) 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 1ed6b78232a8739aa3b1ee1ce7ce2e1d998e3607) Co-Authored-By: Claude Opus 5 (1M context) --- Doc/library/curses.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst index 8820f5ad4891ed..989505f79e68c2 100644 --- a/Doc/library/curses.rst +++ b/Doc/library/curses.rst @@ -32,6 +32,18 @@ Linux and the BSD variants of Unix. Whenever the documentation mentions a *character string* it can be specified as a Unicode string or a byte string. +.. note:: + + Whether curses may be used from several threads + depends on the underlying library and how it was built. + In many implementations, including the default build of ncurses, + the screen state is shared and not thread-safe; + since the blocking and refresh methods + (such as :meth:`~window.getch` and :meth:`~window.refresh`) + release the :term:`GIL`, + unsynchronized use from several threads can then crash the interpreter. + Serialize the calls. + .. seealso:: Module :mod:`curses.ascii`