Skip to content

Instantly share code, notes, and snippets.

@pitrou

pitrou/interrupt.py Secret

Created Mar 4, 2021
Embed
What would you like to do?
import itertools
import signal
import _thread
import threading
def noop_handler(signum, frame):
print("sig", signum)
def set_interrupts(signum):
while True:
signal.raise_signal(signum)
def cycle_handlers(signum):
for handler in itertools.cycle([noop_handler,
signal.SIG_IGN]):
signal.signal(signum, handler)
def main():
signum = signal.SIGINT
signal.signal(signum, noop_handler)
t = threading.Thread(target=set_interrupts, args=(signum,), daemon=True)
t.start()
cycle_handlers(signum)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment