Parallelize db shutdown a bit more

This commit is contained in:
Kovid Goyal 2022-05-01 09:43:59 +05:30
parent 74b218a72a
commit 7f503018ba
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 12 additions and 5 deletions

View File

@ -980,6 +980,10 @@ class DB:
def shutdown_fts(self):
if self.fts_enabled:
self.fts.shutdown()
def join_fts(self):
if self.fts:
self.fts.pool.join()
self.fts = None
def get_connection(self):

View File

@ -2387,6 +2387,7 @@ class Cache:
self.close_called = True
self.shutting_down = True
self.event_dispatcher.close()
self.backend.shutdown_fts()
if self.fts_queue_thread is not None:
self.fts_job_queue.put(None)
from calibre.customize.ui import available_library_closed_plugins
@ -2398,10 +2399,10 @@ class Cache:
traceback.print_exc()
# the fts supervisor thread could be in the middle of committing a
# result to the db, so holding a lock here will cause a deadlock
self.backend.shutdown_fts()
if self.fts_queue_thread is not None:
self.fts_queue_thread.join()
self.fts_queue_thread = None
self.backend.join_fts()
with self.write_lock:
self.backend.close()

View File

@ -210,11 +210,13 @@ class Pool:
w.keep_going = False
for i in range(2*len(self.workers)):
self.jobs_queue.put(quit)
self.supervisor_thread.join()
for w in self.workers:
w.join()
self.workers = []
self.initialized.clear()
def join(self):
self.supervisor_thread.join()
for w in self.workers:
w.join()
self.workers = []
# }}}
def do_check_for_work(self):