summaryrefslogtreecommitdiffhomepage
path: root/bazarr.py
diff options
context:
space:
mode:
authorSmaarn <[email protected]>2020-01-19 14:46:27 +0100
committerSmaarn <[email protected]>2020-01-19 14:46:27 +0100
commit02c3c98cf80b8f447dcc7561ebc1adcd4213ed48 (patch)
tree549f46300da9ffec84d9640c0fade07e01f11439 /bazarr.py
parente26f7fc49e86a6a8aaf78409c565bf1ba37af865 (diff)
downloadbazarr-02c3c98cf80b8f447dcc7561ebc1adcd4213ed48.tar.gz
bazarr-02c3c98cf80b8f447dcc7561ebc1adcd4213ed48.zip
Fixed: when receiving a SIGTERM signal, a smooth shutdown procedure should be performed on children processes.
Reverted the change for Python 2
Diffstat (limited to 'bazarr.py')
-rw-r--r--bazarr.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/bazarr.py b/bazarr.py
index afb9b52c9..f9228e2be 100644
--- a/bazarr.py
+++ b/bazarr.py
@@ -156,7 +156,7 @@ if __name__ == '__main__':
pass
- def daemon(daemonStatus):
+ def daemon(bazarr_runner = lambda: start_bazarr()):
if os.path.exists(stopfile):
try:
os.remove(stopfile)
@@ -172,21 +172,30 @@ if __name__ == '__main__':
except:
print('Unable to delete restart file.')
else:
- start_bazarr(daemonStatus)
+ bazarr_runner()
- daemonStatus = DaemonStatus()
+ bazarr_runner = lambda: start_bazarr()
- def shutdown():
- # indicates that everything should stop
- daemonStatus.stop()
- # emulate a Ctrl C command on itself (bypasses the signal thing but, then, emulates the "Ctrl+C break")
- os.kill(os.getpid(), signal.SIGINT)
+ should_stop = lambda: False
- signal.signal(signal.SIGTERM, lambda signal_no, frame: shutdown())
- start_bazarr(daemonStatus)
+ if PY3:
+ daemonStatus = DaemonStatus()
+
+ def shutdown():
+ # indicates that everything should stop
+ daemonStatus.stop()
+ # emulate a Ctrl C command on itself (bypasses the signal thing but, then, emulates the "Ctrl+C break")
+ os.kill(os.getpid(), signal.SIGINT)
+
+ signal.signal(signal.SIGTERM, lambda signal_no, frame: shutdown())
+
+ should_stop = lambda: daemonStatus.should_stop()
+ bazarr_runner = lambda: start_bazarr(daemonStatus)
+
+ bazarr_runner()
# Keep the script running forever until stop is requested through term or keyboard interrupt
- while not daemonStatus.should_stop():
- daemon(daemonStatus)
+ while not should_stop():
+ daemon(bazarr_runner)
time.sleep(1)