Skip to content

Commit f14a57c

Browse files
gh-154139: Document that curses is not thread-safe
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>
1 parent 5625b18 commit f14a57c

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Doc/library/curses.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ 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+
or wrap them in :meth:`window.use` and :meth:`screen.use`.
46+
3447
.. seealso::
3548

3649
Module :mod:`curses.ascii`

0 commit comments

Comments
 (0)