Optimize code
This commit is contained in:
parent
18891a67fc
commit
8535852699
1 changed files with 62 additions and 60 deletions
|
@ -71,14 +71,29 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin):
|
|||
% (self.current, self.total, self.title))
|
||||
|
||||
def run(self):
|
||||
LOG.debug('Processing thread started')
|
||||
try:
|
||||
self._run()
|
||||
except:
|
||||
utils.ERROR(txt='process_metadata crashed',
|
||||
notify=True,
|
||||
cancel_sync=True)
|
||||
finally:
|
||||
if self.dialog:
|
||||
self.dialog.close()
|
||||
while not self.queue.empty():
|
||||
# We need to empty the queue to let full_sync finish join()
|
||||
self.queue.get()
|
||||
self.queue.task_done()
|
||||
LOG.debug('Processing thread terminated')
|
||||
|
||||
def _run(self):
|
||||
"""
|
||||
Do the work
|
||||
"""
|
||||
LOG.debug('Processing thread started')
|
||||
if self.show_dialog:
|
||||
self.dialog = xbmcgui.DialogProgressBG()
|
||||
self.dialog.create(utils.lang(39714))
|
||||
try:
|
||||
# Init with the very first library section. This will block!
|
||||
section = self.queue.get()
|
||||
self.queue.task_done()
|
||||
|
@ -110,15 +125,10 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin):
|
|||
section.plex_type,
|
||||
self.last_sync)
|
||||
else:
|
||||
try:
|
||||
context.add_update(item['xml'][0],
|
||||
section_name=section.name,
|
||||
section_id=section.id,
|
||||
children=item['children'])
|
||||
except:
|
||||
utils.ERROR(txt='process_metadata crashed',
|
||||
notify=True,
|
||||
cancel_sync=True)
|
||||
self.title = item['xml'][0].get('title')
|
||||
self.processed += 1
|
||||
self.update_progressbar()
|
||||
|
@ -133,11 +143,3 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin):
|
|||
stats.print_stats()
|
||||
LOG.info('cProfile result: ')
|
||||
LOG.info(string_io.getvalue())
|
||||
finally:
|
||||
if self.dialog:
|
||||
self.dialog.close()
|
||||
while not self.queue.empty():
|
||||
# We need to empty the queue to let full_sync finish join()
|
||||
self.queue.get()
|
||||
self.queue.task_done()
|
||||
LOG.debug('Processing thread terminated')
|
||||
|
|
Loading…
Reference in a new issue