Created
March 22, 2019 00:23
-
-
Save Summertime/7f9828c1b9cf3f2bb78abce513504e2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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