From fcb880b741b6ee46544bfdda7da9293ed2fcfd7d Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Dec 2024 14:50:56 +0100 Subject: [PATCH] Force show last quote with SIGUSR1 instead of SIGINT --- quotes.py | 11 +++++++++-- reload.sh | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/quotes.py b/quotes.py index a34ba02..5cd135c 100644 --- a/quotes.py +++ b/quotes.py @@ -7,11 +7,19 @@ from rich.text import Text import json import random import requests +import signal import time from denylist import get_deny_list denylist = get_deny_list() +class Usr1Interrupt(Exception): + def __init__(self, message): + super().__init__(message) + +def handle_sigusr1(sig, frame): + raise Usr1Interrupt("") +signal.signal(signal.SIGUSR1, handle_sigusr1) def refresh_quotes(): res = None @@ -67,7 +75,6 @@ with Live( time.sleep(0.05) time.sleep(30) first_it = False - except KeyboardInterrupt: - # Ctrl-C reloads, kill me with Ctrl-\ + except Usr1Interrupt: first_it = True pass diff --git a/reload.sh b/reload.sh index a515320..47ed097 100755 --- a/reload.sh +++ b/reload.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -kill -INT $(pgrep -f quotes.py) +kill -USR1 $(pgrep -f quotes.py)