aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéo de la Hogue2022-05-11 18:51:25 +0200
committerThéo de la Hogue2022-05-11 18:51:25 +0200
commit181a30b812296ac0dc5738ee5222104f9dc97065 (patch)
tree95aa588ecefa38d882e99be34f935afbaaa38137
parentf898c8bf47744b5829b194d28c4db78494ac5cbe (diff)
downloadargaze-181a30b812296ac0dc5738ee5222104f9dc97065.zip
argaze-181a30b812296ac0dc5738ee5222104f9dc97065.tar.gz
argaze-181a30b812296ac0dc5738ee5222104f9dc97065.tar.bz2
argaze-181a30b812296ac0dc5738ee5222104f9dc97065.tar.xz
Adding an ExitSignalHandler class.
-rw-r--r--src/argaze/utils/MiscFeatures.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/argaze/utils/MiscFeatures.py b/src/argaze/utils/MiscFeatures.py
index 9c62d89..56a77bb 100644
--- a/src/argaze/utils/MiscFeatures.py
+++ b/src/argaze/utils/MiscFeatures.py
@@ -21,3 +21,25 @@ def printProgressBar (iteration:int, total:int, prefix:str = '', suffix:str = ''
# Print New Line on Complete
if iteration == total:
print()
+
+# Handle exit event
+class ExitSignalHandler():
+
+ def __init__(self):
+
+ import signal
+ import threading
+
+ global __exit_event
+ global __on_exit_signal
+
+ __exit_event = threading.Event()
+
+ def __on_exit_signal(signo, _frame):
+ __exit_event.set()
+
+ for sig in ('TERM', 'HUP', 'INT'):
+ signal.signal(getattr(signal, 'SIG'+sig), __on_exit_signal)
+
+ def status(self):
+ return __exit_event.is_set() \ No newline at end of file