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:
parent
6621cc5a8d
commit
afb0960260
2 changed files with 28 additions and 48 deletions
|
@ -14,7 +14,7 @@ import xbmc
|
||||||
import xbmcgui
|
import xbmcgui
|
||||||
import xbmcvfs
|
import xbmcvfs
|
||||||
|
|
||||||
import image_cache_thread
|
from image_cache_thread import ImageCacheThread
|
||||||
from utils import window, settings, language as lang, kodiSQL, tryEncode, \
|
from utils import window, settings, language as lang, kodiSQL, tryEncode, \
|
||||||
tryDecode, IfExists
|
tryDecode, IfExists
|
||||||
|
|
||||||
|
@ -254,20 +254,22 @@ class Artwork():
|
||||||
# removed finished
|
# removed finished
|
||||||
with self.lock:
|
with self.lock:
|
||||||
for thread in self.imageCacheThreads:
|
for thread in self.imageCacheThreads:
|
||||||
if thread.is_finished:
|
if thread.isAlive() is False:
|
||||||
self.imageCacheThreads.remove(thread)
|
self.imageCacheThreads.remove(thread)
|
||||||
# add a new thread or wait and retry if we hit our limit
|
# add a new thread or wait and retry if we hit our limit
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if len(self.imageCacheThreads) < self.imageCacheLimitThreads:
|
if len(self.imageCacheThreads) < self.imageCacheLimitThreads:
|
||||||
newThread = image_cache_thread.ImageCacheThread()
|
thread = ImageCacheThread(
|
||||||
newThread.set_url(self.double_urlencode(url))
|
self.xbmc_username,
|
||||||
newThread.set_host(self.xbmc_host, self.xbmc_port)
|
self.xbmc_password,
|
||||||
newThread.set_auth(self.xbmc_username, self.xbmc_password)
|
"http://%s:%s/image/image://%s"
|
||||||
newThread.start()
|
% (self.xbmc_host,
|
||||||
self.imageCacheThreads.append(newThread)
|
self.xbmc_port,
|
||||||
|
self.double_urlencode(url)))
|
||||||
|
thread.start()
|
||||||
|
self.imageCacheThreads.append(thread)
|
||||||
return
|
return
|
||||||
log.debug("Waiting for empty queue spot: %s"
|
log.error('Waiting for queue spot here')
|
||||||
% len(self.imageCacheThreads))
|
|
||||||
xbmc.sleep(50)
|
xbmc.sleep(50)
|
||||||
|
|
||||||
def cacheTexture(self, url):
|
def cacheTexture(self, url):
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
#################################################################################################
|
###############################################################################
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import requests
|
import requests
|
||||||
|
@ -9,51 +8,30 @@ import requests
|
||||||
# Disable annoying requests warnings
|
# Disable annoying requests warnings
|
||||||
import requests.packages.urllib3
|
import requests.packages.urllib3
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
#################################################################################################
|
###############################################################################
|
||||||
|
|
||||||
log = logging.getLogger("PLEX."+__name__)
|
log = logging.getLogger("PLEX."+__name__)
|
||||||
|
|
||||||
#################################################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
class ImageCacheThread(threading.Thread):
|
class ImageCacheThread(threading.Thread):
|
||||||
|
def __init__(self, xbmc_username, xbmc_password, url):
|
||||||
url_to_process = None
|
self.xbmc_username = xbmc_username
|
||||||
is_finished = False
|
self.xbmc_password = xbmc_password
|
||||||
|
self.url = url
|
||||||
xbmc_host = ""
|
|
||||||
xbmc_port = ""
|
|
||||||
xbmc_username = ""
|
|
||||||
xbmc_password = ""
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
|
|
||||||
threading.Thread.__init__(self)
|
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):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
response = requests.head(
|
requests.head(
|
||||||
url=("http://%s:%s/image/image://%s"
|
url=self.url,
|
||||||
% (self.xbmc_host, self.xbmc_port, self.url_to_process)),
|
|
||||||
auth=(self.xbmc_username, self.xbmc_password),
|
auth=(self.xbmc_username, self.xbmc_password),
|
||||||
timeout=(5, 5))
|
timeout=(0.01, 0.01))
|
||||||
# We don't need the result
|
except requests.Timeout:
|
||||||
except Exception:
|
# We don't need the result, only trigger Kodi to start download
|
||||||
pass
|
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())
|
||||||
|
|
Loading…
Reference in a new issue