Optimize image_cache_thread

- BUT: lead to DOS-seeming behavior and ConnectionError: ('Connection
aborted.', error(10053)) from http://image.tmdb.org/
This commit is contained in:
tomkat83 2016-09-17 11:23:31 +02:00
parent 6621cc5a8d
commit afb0960260
2 changed files with 28 additions and 48 deletions

View file

@ -14,7 +14,7 @@ import xbmc
import xbmcgui
import xbmcvfs
import image_cache_thread
from image_cache_thread import ImageCacheThread
from utils import window, settings, language as lang, kodiSQL, tryEncode, \
tryDecode, IfExists
@ -254,20 +254,22 @@ class Artwork():
# removed finished
with self.lock:
for thread in self.imageCacheThreads:
if thread.is_finished:
if thread.isAlive() is False:
self.imageCacheThreads.remove(thread)
# add a new thread or wait and retry if we hit our limit
with self.lock:
if len(self.imageCacheThreads) < self.imageCacheLimitThreads:
newThread = image_cache_thread.ImageCacheThread()
newThread.set_url(self.double_urlencode(url))
newThread.set_host(self.xbmc_host, self.xbmc_port)
newThread.set_auth(self.xbmc_username, self.xbmc_password)
newThread.start()
self.imageCacheThreads.append(newThread)
thread = ImageCacheThread(
self.xbmc_username,
self.xbmc_password,
"http://%s:%s/image/image://%s"
% (self.xbmc_host,
self.xbmc_port,
self.double_urlencode(url)))
thread.start()
self.imageCacheThreads.append(thread)
return
log.debug("Waiting for empty queue spot: %s"
% len(self.imageCacheThreads))
log.error('Waiting for queue spot here')
xbmc.sleep(50)
def cacheTexture(self, url):

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
#################################################################################################
###############################################################################
import logging
import threading
import requests
@ -9,51 +8,30 @@ import requests
# Disable annoying requests warnings
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
#################################################################################################
###############################################################################
log = logging.getLogger("PLEX."+__name__)
#################################################################################################
###############################################################################
class ImageCacheThread(threading.Thread):
url_to_process = None
is_finished = False
xbmc_host = ""
xbmc_port = ""
xbmc_username = ""
xbmc_password = ""
def __init__(self):
def __init__(self, xbmc_username, xbmc_password, url):
self.xbmc_username = xbmc_username
self.xbmc_password = xbmc_password
self.url = url
threading.Thread.__init__(self)
def set_url(self, url):
self.url_to_process = url
def set_host(self, host, port):
self.xbmc_host = host
self.xbmc_port = port
def set_auth(self, username, password):
self.xbmc_username = username
self.xbmc_password = password
def run(self):
try:
response = requests.head(
url=("http://%s:%s/image/image://%s"
% (self.xbmc_host, self.xbmc_port, self.url_to_process)),
requests.head(
url=self.url,
auth=(self.xbmc_username, self.xbmc_password),
timeout=(5, 5))
# We don't need the result
except Exception:
timeout=(0.01, 0.01))
except requests.Timeout:
# We don't need the result, only trigger Kodi to start download
pass
self.is_finished = True
except Exception as e:
log.error('Encountered exception: %s' % e)
import traceback
log.error("Traceback:\n%s" % traceback.format_exc())