mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2026-09-26 15:26:13 +00:00
use multiprocessing to wrap flask and use SIGTERM to save DB
This commit is contained in:
+14
-1
@@ -6,6 +6,19 @@
|
||||
# Read more https://github.com/dgtlmoon/changedetection.io/wiki
|
||||
|
||||
from changedetectionio import changedetection
|
||||
import multiprocessing
|
||||
|
||||
if __name__ == '__main__':
|
||||
changedetection.main()
|
||||
|
||||
parse_process = multiprocessing.Process(target=changedetection.main)
|
||||
parse_process.daemon = True
|
||||
parse_process.start()
|
||||
import time
|
||||
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
#parse_process.terminate() not needed, because this process will issue it to the sub-process anyway
|
||||
print ("Exited - CTRL+C")
|
||||
|
||||
@@ -1263,7 +1263,6 @@ def notification_runner():
|
||||
global notification_debug_log
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
while not app.config.exit.is_set():
|
||||
try:
|
||||
# At the moment only one thread runs (single runner)
|
||||
|
||||
@@ -20,11 +20,10 @@ def sigterm_handler(_signo, _stack_frame):
|
||||
global app
|
||||
global datastore
|
||||
|
||||
print('Shutdown: got SIGINT, writing DB')
|
||||
datastore.sync_to_json()
|
||||
print('sync_to_json() done')
|
||||
eventlet.is_accepting = False
|
||||
app.config.exit.set()
|
||||
datastore.sync_to_json()
|
||||
print('Shutdown: Got SIGTERM, DB saved to disk')
|
||||
raise SystemExit
|
||||
|
||||
|
||||
|
||||
@@ -93,7 +92,7 @@ def main():
|
||||
|
||||
datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], version_tag=__version__)
|
||||
app = changedetection_app(app_config, datastore)
|
||||
signal.signal(signal.SIGINT, sigterm_handler)
|
||||
signal.signal(signal.SIGTERM, sigterm_handler)
|
||||
|
||||
# Go into cleanup mode
|
||||
if do_cleanup:
|
||||
|
||||
Reference in New Issue
Block a user