Skip to content

curses' sigwinch handler isn't visible from python #48199

Closed as not planned
Closed as not planned

Description

@shish
mannequin
BPO 3949
Nosy @vstinner, @devdanzin, @serhiy-storchaka
Dependencies
  • bpo-3948: readline steals sigwinch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2008-09-23.21:18:28.003>
    labels = ['extension-modules', 'type-bug', '3.7']
    title = "curses' sigwinch handler isn't visible from python"
    updated_at = <Date 2017-11-02.11:42:38.832>
    user = 'https://bugs.python.org/shish'

    bugs.python.org fields:

    activity = <Date 2017-11-02.11:42:38.832>
    actor = 'vstinner'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2008-09-23.21:18:28.003>
    creator = 'shish'
    dependencies = ['3948']
    files = []
    hgrepos = []
    issue_num = 3949
    keywords = []
    message_count = 4.0
    messages = ['73668', '87950', '88023', '305419']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'ajaksu2', 'shish', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue3949'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7']

    Activity

    1. shish commented on Sep 23, 2008

      shishmannequin
      MannequinAuthor

      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)

    2. added
      extension-modules
      on Sep 23, 2008
    3. devdanzin commented on May 17, 2009

      devdanzinmannequin
      Mannequin

      Shish,
      Can you provide a short test script? I think this might also be related
      to bpo-1687125.

    4. added
      type-bug
      on May 17, 2009
    5. shish commented on May 18, 2009

      shishmannequin
      MannequinAuthor

      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

      ~~~~~~~~~~~~~~

      import curses
      import signal
      
      curses.initscr()
      old_winch = signal.getsignal(signal.SIGWINCH)
      curses.endwin()
      print old_winch
    6. vstinner commented on Nov 2, 2017

      @vstinner
      Member

      The signal(SIGWINCH, SIG_IGN) call doesn't return the old, working signal handler; it returns 0

      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.

    7. transferred this issue fromon Apr 10, 2022
    8. serhiy-storchaka commented on Jun 26, 2026

      @serhiy-storchaka
      Member

      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).

      Closing as not planned.

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

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      extension-modulestype-bug

      Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions