Reduce CPU strain for artwork caching progress

- Fixes #477
This commit is contained in:
Croneter 2018-05-18 15:59:26 +02:00
parent d706f38f91
commit 84c2aa7fa0
2 changed files with 20 additions and 24 deletions

View file

@ -65,23 +65,17 @@ class Image_Cache_Thread(Thread):
LOG.info("---===### Stopped Image_Cache_Thread ###===---") LOG.info("---===### Stopped Image_Cache_Thread ###===---")
return return
sleep(1000) sleep(1000)
# Update the caching state in the PKC settings. Avoid saving '0'
counter += 1
if counter > 10:
counter = 0
length = queue.qsize()
if not set_zero:
settings('caching_artwork_count', value=str(length))
set_zero = False if length else True
elif length:
settings('caching_artwork_count', value=str(length))
set_zero = False
try: try:
url = queue.get(block=False) url = queue.get(block=False)
except Empty: except Empty:
if not set_zero:
# Avoid saving '0' all the time
set_zero = True
settings('caching_artwork_count', value='0')
sleep(1000) sleep(1000)
continue continue
set_zero = False
if isinstance(url, ArtworkSyncMessage): if isinstance(url, ArtworkSyncMessage):
if state.IMAGE_SYNC_NOTIFICATIONS: if state.IMAGE_SYNC_NOTIFICATIONS:
dialog('notification', dialog('notification',
@ -133,6 +127,11 @@ class Image_Cache_Thread(Thread):
# We did not even get a timeout # We did not even get a timeout
break break
queue.task_done() queue.task_done()
# Update the caching state in the PKC settings.
counter += 1
if counter > 20:
counter = 0
settings('caching_artwork_count', value=str(queue.qsize()))
# Sleep for a bit to reduce CPU strain # Sleep for a bit to reduce CPU strain
sleep(sleep_between) sleep(sleep_between)
LOG.info("---===### Stopped Image_Cache_Thread ###===---") LOG.info("---===### Stopped Image_Cache_Thread ###===---")

View file

@ -60,25 +60,17 @@ class ThreadedProcessFanart(Thread):
LOG.info("---===### Stopped FanartSync ###===---") LOG.info("---===### Stopped FanartSync ###===---")
return return
sleep(1000) sleep(1000)
# Update the caching state in the PKC settings. Avoid saving '0'
counter += 1
if counter > 10:
counter = 0
length = queue.qsize()
if not set_zero:
settings('fanarttv_lookups', value=str(length))
set_zero = False if length else True
elif length:
settings('fanarttv_lookups', value=str(length))
set_zero = False
# grabs Plex item from queue # grabs Plex item from queue
try: try:
item = queue.get(block=False) item = queue.get(block=False)
except Empty: except Empty:
if not set_zero:
# Avoid saving '0' all the time
set_zero = True
settings('fanarttv_lookups', value='0')
sleep(200) sleep(200)
continue continue
set_zero = False
if isinstance(item, ArtworkSyncMessage): if isinstance(item, ArtworkSyncMessage):
if state.IMAGE_SYNC_NOTIFICATIONS: if state.IMAGE_SYNC_NOTIFICATIONS:
dialog('notification', dialog('notification',
@ -98,5 +90,10 @@ class ThreadedProcessFanart(Thread):
LOG.debug('Done getting fanart for Plex id %s', item['plex_id']) LOG.debug('Done getting fanart for Plex id %s', item['plex_id'])
with plexdb.Get_Plex_DB() as plex_db: with plexdb.Get_Plex_DB() as plex_db:
plex_db.set_fanart_synched(item['plex_id']) plex_db.set_fanart_synched(item['plex_id'])
# Update the caching state in the PKC settings. Avoid saving '0'
counter += 1
if counter > 10:
counter = 0
settings('fanarttv_lookups', value=str(queue.qsize()))
queue.task_done() queue.task_done()
LOG.debug("---===### Stopped FanartSync ###===---") LOG.debug("---===### Stopped FanartSync ###===---")