Skip to content

Instantly share code, notes, and snippets.

@Summertime
Created March 22, 2019 00:23
Show Gist options
  • Save Summertime/7f9828c1b9cf3f2bb78abce513504e2b to your computer and use it in GitHub Desktop.
Save Summertime/7f9828c1b9cf3f2bb78abce513504e2b to your computer and use it in GitHub Desktop.
from signal import signal as _signal
from collections import defaultdict as _defaultdict
__all__ = ['pls_handle']
_pls_handlets = _defaultdict(list)
def _the_pls_handle_signal_handler(signalnum, frame):
for function in _pls_handlets[signalnum]:
function(signalnum, frame)
def pls_handle(signalnum):
def _scoped_pls_handle(function):
_signal(signalnum, _the_pls_handle_signal_handler)
_pls_handlets[signalnum].append(function)
return function
return _scoped_pls_handle
from pls_handle import pls_handle
from signal import SIGWINCH, pause
import shutil
@pls_handle(SIGWINCH)
def sigwinch_handler(signalnum, frame):
print(signalnum)
@pls_handle(SIGWINCH)
def sigwinch_handler2(signalnum, frame):
print(shutil.get_terminal_size((80, 20)))
while 1:
pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment