You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
curses' sigwinch handler isn't visible from python #48199
after the first initscr() sigwinch is handled as expected, but then my
app needs to ignore sigwinch, leave curses to view the output from
something, come back into curses, and start listening for sigwinch
again. The signal(SIGWINCH, SIG_IGN) call doesn't return the old,
working signal handler; it returns 0 -- thus trying to re-set the
signal handler doesn't work.
(The reason for ignoring the signal is that if the window is resized
while the external app is running, python's wait() is interrupted)
Having the handler visible from python would also make curses play
nicer with readline, as the app could mediate signal handling (see
issue bpo-3948)
in its simplest form, this shows the bug -- signal.getsignal does not
return the original signal handler (the "tell the app to resize itself"
one that curses installs), and so, the original signal handler cannot
be re-activated after being temporarily disabled
This is not fixable in curses. The SIGWINCH handler is installed by ncurses itself, at the C level, when initscr() runs — _curses never registers it through Python's signal module.
Python's signal module only tracks handlers set through itself, so signal.getsignal(SIGWINCH) returns its cached value (SIG_DFL), never a handler installed directly by a C library. That is the general limitation already tracked in gh-57494 ("signal module ignores external signal changes"), not something curses can expose — Python cannot hand back a C handler as a callable.
The practical resize trouble behind this (readline freezing LINES/COLUMNS) is the same problem as gh-46927, addressed by PR #133585 (rl_change_environment = 0).
Activity
shish commentedon Sep 23, 2008
after the first initscr() sigwinch is handled as expected, but then my
app needs to ignore sigwinch, leave curses to view the output from
something, come back into curses, and start listening for sigwinch
again. The signal(SIGWINCH, SIG_IGN) call doesn't return the old,
working signal handler; it returns 0 -- thus trying to re-set the
signal handler doesn't work.
(The reason for ignoring the signal is that if the window is resized
while the external app is running, python's wait() is interrupted)
Having the handler visible from python would also make curses play
nicer with readline, as the app could mediate signal handling (see
issue bpo-3948)
devdanzin commentedon May 17, 2009
Shish,
Can you provide a short test script? I think this might also be related
to bpo-1687125.
shish commentedon May 18, 2009
in its simplest form, this shows the bug -- signal.getsignal does not
return the original signal handler (the "tell the app to resize itself"
one that curses installs), and so, the original signal handler cannot
be re-activated after being temporarily disabled
~~~~~~~~~~~~~~
vstinner commentedon Nov 2, 2017
See bpo-13285: "signal module ignores external signal changes".
By the way, I recently modified test_curses to save/restore signal handlers: see bpo-31629.
serhiy-storchaka commentedon Jun 26, 2026
This is not fixable in
curses. TheSIGWINCHhandler is installed by ncurses itself, at the C level, wheninitscr()runs —_cursesnever registers it through Python'ssignalmodule.Python's
signalmodule only tracks handlers set through itself, sosignal.getsignal(SIGWINCH)returns its cached value (SIG_DFL), never a handler installed directly by a C library. That is the general limitation already tracked in gh-57494 ("signal module ignores external signal changes"), not something curses can expose — Python cannot hand back a C handler as a callable.The practical resize trouble behind this (readline freezing
LINES/COLUMNS) is the same problem as gh-46927, addressed by PR #133585 (rl_change_environment = 0).Closing as not planned.