Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow signal handling interoperability with raw display #557

Merged
merged 1 commit into from May 19, 2023

Conversation

AnonymouX47
Copy link
Contributor

@AnonymouX47 AnonymouX47 commented May 19, 2023

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
5 checks passed
@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.

None yet

2 participants