summaryrefslogtreecommitdiffhomepage
path: root/bazarr.py
diff options
context:
space:
mode:
authorSmaarn <[email protected]>2020-05-24 11:45:28 +0200
committerSmaarn <[email protected]>2020-05-24 14:58:41 +0200
commit7e304001b62a0d6c68c06c8c9283b4e55a233d32 (patch)
tree7236091d5b981627cb773d4e144b33c33d1efcf0 /bazarr.py
parent834228f8883f44b402ed2ea58245c301bb056b54 (diff)
downloadbazarr-7e304001b62a0d6c68c06c8c9283b4e55a233d32.tar.gz
bazarr-7e304001b62a0d6c68c06c8c9283b4e55a233d32.zip
Rework on child process management.
When receiving the SIGTERM signal, swallow it and terminate latest created child process Catch ChildProcessError (occurs when child process is terminated by the current python script on mac os x)
Diffstat (limited to 'bazarr.py')
-rw-r--r--bazarr.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/bazarr.py b/bazarr.py
index 594154e13..a3e17189a 100644
--- a/bazarr.py
+++ b/bazarr.py
@@ -2,6 +2,7 @@
import os
import platform
+import signal
import subprocess
import sys
import time
@@ -37,11 +38,18 @@ def end_child_process(ep):
except:
pass
+def terminate_child_process(ep):
+ try:
+ ep.terminate()
+ except:
+ pass
+
def start_bazarr():
script = [sys.executable, "-u", os.path.normcase(os.path.join(dir_name, 'bazarr', 'main.py'))] + sys.argv[1:]
ep = subprocess.Popen(script, stdout=None, stderr=None, stdin=subprocess.DEVNULL)
atexit.register(end_child_process, ep=ep)
+ signal.signal(signal.SIGTERM, lambda signal_no, frame: terminate_child_process(ep))
def check_status():
@@ -92,6 +100,6 @@ if __name__ == '__main__':
else:
os.wait()
time.sleep(1)
- except (KeyboardInterrupt, SystemExit):
+ except (KeyboardInterrupt, SystemExit, ChildProcessError):
print('Bazarr exited.')
sys.exit(0)