Skip to content

Commit ed83cc2

Browse files
[3.15] 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 1ed6b78) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent ed38a08 commit ed83cc2

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Doc/library/curses.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ Linux and the BSD variants of Unix.
3131
Whenever the documentation mentions a *character string* it can be specified
3232
as a Unicode string or a byte string.
3333

34+
.. note::
35+
36+
Whether curses may be used from several threads
37+
depends on the underlying library and how it was built.
38+
In many implementations, including the default build of ncurses,
39+
the screen state is shared and not thread-safe;
40+
since the blocking and refresh methods
41+
(such as :meth:`~window.getch` and :meth:`~window.refresh`)
42+
release the :term:`GIL`,
43+
unsynchronized use from several threads can then crash the interpreter.
44+
Serialize the calls.
45+
3446
.. seealso::
3547

3648
Module :mod:`curses.ascii`

0 commit comments

Comments
 (0)