mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Fix the metadata backup thread to more reliably flush an in_limbo id
This commit is contained in:
parent
503038f39f
commit
05be08a9ee
@ -638,8 +638,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
time.sleep(2)
|
||||
if mb is not None:
|
||||
mb.flush()
|
||||
self.hide_windows()
|
||||
return True
|
||||
|
||||
|
@ -42,6 +42,7 @@ class MetadataBackup(Thread): # {{{
|
||||
|
||||
def stop(self):
|
||||
self.keep_running = False
|
||||
self.flush()
|
||||
# Break cycles so that this object doesn't hold references to db
|
||||
self.do_write = self.get_metadata_for_dump = self.clear_dirtied = \
|
||||
self.set_dirtied = self.db = None
|
||||
@ -57,7 +58,10 @@ class MetadataBackup(Thread): # {{{
|
||||
except:
|
||||
# Happens during interpreter shutdown
|
||||
break
|
||||
if not self.keep_running:
|
||||
break
|
||||
|
||||
self.in_limbo = id_
|
||||
try:
|
||||
path, mi = self.get_metadata_for_dump(id_)
|
||||
except:
|
||||
@ -72,10 +76,10 @@ class MetadataBackup(Thread): # {{{
|
||||
continue
|
||||
|
||||
# at this point the dirty indication is off
|
||||
|
||||
if mi is None:
|
||||
continue
|
||||
self.in_limbo = id_
|
||||
if not self.keep_running:
|
||||
break
|
||||
|
||||
# Give the GUI thread a chance to do something. Python threads don't
|
||||
# have priorities, so this thread would naturally keep the processor
|
||||
@ -89,6 +93,9 @@ class MetadataBackup(Thread): # {{{
|
||||
traceback.print_exc()
|
||||
continue
|
||||
|
||||
if not self.keep_running:
|
||||
break
|
||||
|
||||
time.sleep(0.1) # Give the GUI thread a chance to do something
|
||||
try:
|
||||
self.do_write(path, raw)
|
||||
@ -102,6 +109,7 @@ class MetadataBackup(Thread): # {{{
|
||||
prints('Failed to write backup metadata for id:', id_,
|
||||
'again, giving up')
|
||||
continue
|
||||
|
||||
self.in_limbo = None
|
||||
|
||||
def flush(self):
|
||||
@ -111,6 +119,7 @@ class MetadataBackup(Thread): # {{{
|
||||
self.db.dirtied([self.in_limbo])
|
||||
except:
|
||||
traceback.print_exc()
|
||||
self.in_limbo = None
|
||||
|
||||
def write(self, path, raw):
|
||||
with lopen(path, 'wb') as f:
|
||||
|
Loading…
x
Reference in New Issue
Block a user