aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xepy.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/epy.py b/epy.py
index dd77e54..fb44586 100755
--- a/epy.py
+++ b/epy.py
@@ -43,6 +43,7 @@ import multiprocessing
import os
import re
import shutil
+import signal
import sqlite3
import subprocess
import sys
@@ -3856,6 +3857,17 @@ def preread(stdscr, filepath: str):
reader = Reader(screen=stdscr, ebook=ebook, config=config, state=state)
+ def handle_signal(signum, _):
+ """
+ Method to raise SystemExit based on signal received
+ to trigger `try-finally` clause
+ """
+ msg = f"[{os.getpid()}] killed"
+ if signal.Signals(signum) == signal.SIGTERM:
+ msg = f"[{os.getpid()}] terminated"
+ sys.exit(msg)
+ signal.signal(signal.SIGTERM, handle_signal)
+
try:
reader.run_counting_letters()