mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make shutting down the fts pool more robust
Fixes a deadlock and gives the worker threads a chance to clean exit
This commit is contained in:
parent
89411a763e
commit
74b218a72a
@ -2379,8 +2379,9 @@ class Cache:
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
||||
@write_api
|
||||
@api
|
||||
def close(self):
|
||||
with self.write_lock:
|
||||
if hasattr(self, 'close_called'):
|
||||
return
|
||||
self.close_called = True
|
||||
@ -2395,10 +2396,13 @@ class Cache:
|
||||
except Exception:
|
||||
import traceback
|
||||
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
|
||||
with self.write_lock:
|
||||
self.backend.close()
|
||||
|
||||
@property
|
||||
|
@ -129,6 +129,7 @@ class Pool:
|
||||
self.workers = []
|
||||
self.initialized = Event()
|
||||
self.dbref = dbref
|
||||
self.keep_going = True
|
||||
|
||||
def initialize(self):
|
||||
if not self.initialized.is_set():
|
||||
@ -202,9 +203,12 @@ class Pool:
|
||||
|
||||
def shutdown(self):
|
||||
if self.initialized.is_set():
|
||||
self.keep_going = False
|
||||
for i in range(2):
|
||||
self.supervise_queue.put(quit)
|
||||
for w in self.workers:
|
||||
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:
|
||||
@ -219,7 +223,7 @@ class Pool:
|
||||
db.queue_next_fts_job()
|
||||
|
||||
def supervise(self):
|
||||
while True:
|
||||
while self.keep_going:
|
||||
x = self.supervise_queue.get()
|
||||
try:
|
||||
if x is check_for_work:
|
||||
|
Loading…
x
Reference in New Issue
Block a user