mirror of
https://github.com/morpheus65535/bazarr
synced 2025-01-03 05:25:28 +00:00
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)
This commit is contained in:
parent
834228f888
commit
7e304001b6
1 changed files with 9 additions and 1 deletions
10
bazarr.py
10
bazarr.py
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
@ -37,11 +38,18 @@ def end_child_process(ep):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def terminate_child_process(ep):
|
||||||
|
try:
|
||||||
|
ep.terminate()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def start_bazarr():
|
def start_bazarr():
|
||||||
script = [sys.executable, "-u", os.path.normcase(os.path.join(dir_name, 'bazarr', 'main.py'))] + sys.argv[1:]
|
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)
|
ep = subprocess.Popen(script, stdout=None, stderr=None, stdin=subprocess.DEVNULL)
|
||||||
atexit.register(end_child_process, ep=ep)
|
atexit.register(end_child_process, ep=ep)
|
||||||
|
signal.signal(signal.SIGTERM, lambda signal_no, frame: terminate_child_process(ep))
|
||||||
|
|
||||||
|
|
||||||
def check_status():
|
def check_status():
|
||||||
|
@ -92,6 +100,6 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
os.wait()
|
os.wait()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit, ChildProcessError):
|
||||||
print('Bazarr exited.')
|
print('Bazarr exited.')
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
Loading…
Reference in a new issue