Skip to content

Allow signal handling interoperability with raw display - #557

Merged
penguinolog merged 1 commit into
urwid:masterfrom
AnonymouX47:fix-signal-handling
May 19, 2023
Merged

Allow signal handling interoperability with raw display#557
penguinolog merged 1 commit into
urwid:masterfrom
AnonymouX47:fix-signal-handling

Conversation

@AnonymouX47

@AnonymouX47 AnonymouX47 commented May 19, 2023

Copy link
Copy Markdown
Contributor
Checklist
  • I've ensured that similar functionality has not already been implemented
  • I've ensured that similar functionality has not earlier been proposed and declined
  • I've branched off the master or python-dual-support branch
  • I've merged fresh upstream into my branch recently
  • I've ran tox successfully in local environment
  • I've included docstrings and/or documentation and/or examples for my code (if this is a new feature)
Description:

Currently, it's either urwid's handler or another... except an/some aggregate handler(s) (which calls urwid's and the other(s)) is/are installed by the program using the different libraries, which in certain cases might either be difficult to trace where/when each library installs its handler or be implementation detail which could change without notice.

This changes ensure any previously installed signal handlers are stored, restored and invoked (by raw_display.Screen's signal handlers).
This prevents breaking functionality of other libraries which install signal handlers and are unaware of urwid.

I encountered this issue while developing a library where SIGWINCH would be really useful.

Sample test code:

import os
import signal
import urwid

def sigwinch_handler(signum, frame):
    text.set_text("x".join(map(str, os.get_terminal_size())))

signal.signal(signal.SIGWINCH, sigwinch_handler)

text = urwid.Text("x".join(map(str, os.get_terminal_size())), "center")
try:
    urwid.MainLoop(urwid.Filler(text)).run()
except KeyboardInterrupt:
    pass

- Fix: Store, restore and invoke the previous handlers for handled
  signals, if any.

  - Prevents breaking functionality of other libraries which install
    signal handlers and are unaware of `urwid`.
@AnonymouX47 AnonymouX47 changed the title Allow signal handling interoperability Allow signal handling interoperability with raw display May 19, 2023
@penguinolog
penguinolog merged commit 3353b08 into urwid:master May 19, 2023
@AnonymouX47
AnonymouX47 deleted the fix-signal-handling branch May 20, 2023 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants