From 47dd76fced2f48bafe21b720a65dc01de620b491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Thu, 22 Aug 2019 11:42:52 -0400 Subject: [PATCH] Continuing development. --- bazarr/database.py | 21 ++++++++++++--------- bazarr/main.py | 7 ++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/bazarr/database.py b/bazarr/database.py index 17e9fc619..c1f7ab2d9 100644 --- a/bazarr/database.py +++ b/bazarr/database.py @@ -4,17 +4,20 @@ import atexit from get_args import args from peewee import * from playhouse.sqliteq import SqliteQueueDatabase -from playhouse.reflection import generate_models from helper import path_replace, path_replace_movie, path_replace_reverse, path_replace_reverse_movie database = SqliteQueueDatabase( os.path.join(args.config_dir, 'db', 'bazarr.db'), - use_gevent=False, # Use the standard library "threading" module. - autostart=False, # The worker thread now must be started manually. + use_gevent=False, + autostart=True, queue_max_size=256, # Max. # of pending writes that can accumulate. results_timeout=30.0) # Max. time to wait for query to be executed. +#database = SqliteDatabase(os.path.join(args.config_dir, 'db', 'bazarr.db'), pragmas={ +# 'journal_mode': 'wal', +# 'cache_size': -1024 * 8}) + @database.func('path_substitution') def path_substitution(path): @@ -168,13 +171,7 @@ class TableSettingsNotifier(BaseModel): table_name = 'table_settings_notifier' -@atexit.register -def _stop_worker_threads(): - database.stop() - - def database_init(): - database.start() database.connect() models_list = [TableShows, TableEpisodes, TableMovies, TableHistory, TableHistoryMovie, TableSettingsLanguages, @@ -190,3 +187,9 @@ def database_init(): System.configured: 0 } ).execute() + + +@atexit.register +def _stop_worker_threads(): + database.close() + database.stop() diff --git a/bazarr/main.py b/bazarr/main.py index 9be15722a..e3a366b9f 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -22,7 +22,7 @@ import operator from get_args import args from init import * -from database import database_init, TableEpisodes, TableShows, TableMovies, TableHistory, TableHistoryMovie, \ +from database import database, database_init, TableEpisodes, TableShows, TableMovies, TableHistory, TableHistoryMovie, \ TableSettingsLanguages, TableSettingsNotifier, System # Initiate database @@ -187,7 +187,10 @@ def shutdown(): else: stop_file.write('') stop_file.close() + database.close() + database.stop() server.stop() + sys.exit(0) @route(base_url + 'restart') @@ -206,6 +209,8 @@ def restart(): logging.info('Bazarr is being restarted...') restart_file.write('') restart_file.close() + database.close() + database.stop() @route(base_url + 'wizard')