aboutsummaryrefslogtreecommitdiffstats
path: root/epy.py
diff options
context:
space:
mode:
authorbenadha <benawiadha@gmail.com>2022-02-20 21:34:08 +0700
committerbenadha <benawiadha@gmail.com>2022-02-20 21:34:08 +0700
commit3ef26d04ad50a884b3c0e6dced32f47375b90939 (patch)
tree74bc4d930ee4d2f71d2e69bd439c0a621b2fdf16 /epy.py
parent78cd38d1e31b619328404481ba0a6d80909fd33c (diff)
downloadepy-3ef26d04ad50a884b3c0e6dced32f47375b90939.tar.gz
Add signal handler
Diffstat (limited to 'epy.py')
-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()