Cleaned multi threading
This commit is contained in:
parent
1697e38342
commit
4332d08292
1 changed files with 23 additions and 16 deletions
|
@ -56,13 +56,16 @@ class ThreadedGetMetadata(threading.Thread):
|
||||||
try:
|
try:
|
||||||
updateItem = self.queue.get(block=False)
|
updateItem = self.queue.get(block=False)
|
||||||
# Empty queue
|
# Empty queue
|
||||||
except:
|
except Queue.Empty:
|
||||||
continue
|
continue
|
||||||
# Download Metadata
|
# Download Metadata
|
||||||
plexElement = plx.GetPlexMetadata(updateItem['itemId'])
|
try:
|
||||||
updateItem['XML'] = plexElement
|
updateItem['XML'] = plx.GetPlexMetadata(updateItem['itemId'])
|
||||||
|
except:
|
||||||
|
raise
|
||||||
# place item into out queue
|
# place item into out queue
|
||||||
self.out_queue.put(updateItem)
|
self.out_queue.put(updateItem)
|
||||||
|
del updateItem
|
||||||
# Keep track of where we are at
|
# Keep track of where we are at
|
||||||
with self.lock:
|
with self.lock:
|
||||||
getMetadataCount += 1
|
getMetadataCount += 1
|
||||||
|
@ -108,7 +111,7 @@ class ThreadedProcessMetadata(threading.Thread):
|
||||||
try:
|
try:
|
||||||
updateItem = self.queue.get(block=False)
|
updateItem = self.queue.get(block=False)
|
||||||
# Empty queue
|
# Empty queue
|
||||||
except:
|
except Queue.Empty:
|
||||||
continue
|
continue
|
||||||
# Do the work; lock to be sure we've only got 1 Thread
|
# Do the work; lock to be sure we've only got 1 Thread
|
||||||
plexitem = updateItem['XML']
|
plexitem = updateItem['XML']
|
||||||
|
@ -118,14 +121,17 @@ class ThreadedProcessMetadata(threading.Thread):
|
||||||
title = updateItem['title']
|
title = updateItem['title']
|
||||||
itemSubFkt = getattr(item, method)
|
itemSubFkt = getattr(item, method)
|
||||||
with self.lock:
|
with self.lock:
|
||||||
itemSubFkt(
|
try:
|
||||||
plexitem,
|
itemSubFkt(
|
||||||
viewtag=viewName,
|
plexitem,
|
||||||
viewid=viewId
|
viewtag=viewName,
|
||||||
)
|
viewid=viewId
|
||||||
# Keep track of where we are at
|
)
|
||||||
processMetadataCount += 1
|
# Keep track of where we are at
|
||||||
processingViewName = title
|
processMetadataCount += 1
|
||||||
|
processingViewName = title
|
||||||
|
except:
|
||||||
|
raise
|
||||||
# signals to queue job is done
|
# signals to queue job is done
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|
||||||
|
@ -629,8 +635,7 @@ class LibrarySync(threading.Thread):
|
||||||
'method': method,
|
'method': method,
|
||||||
'viewName': viewName,
|
'viewName': viewName,
|
||||||
'viewId': viewId})
|
'viewId': viewId})
|
||||||
# Update the Kodi popup info
|
return
|
||||||
return self.updatelist, self.allPlexElementsId
|
|
||||||
|
|
||||||
def GetAndProcessXMLs(self, itemType):
|
def GetAndProcessXMLs(self, itemType):
|
||||||
"""
|
"""
|
||||||
|
@ -651,7 +656,7 @@ class LibrarySync(threading.Thread):
|
||||||
self.logMsg("Starting sync threads", 1)
|
self.logMsg("Starting sync threads", 1)
|
||||||
self.logMsg("=====================", 1)
|
self.logMsg("=====================", 1)
|
||||||
getMetadataQueue = Queue.Queue()
|
getMetadataQueue = Queue.Queue()
|
||||||
processMetadataQueue = Queue.Queue()
|
processMetadataQueue = Queue.Queue(maxsize=100)
|
||||||
getMetadataLock = threading.Lock()
|
getMetadataLock = threading.Lock()
|
||||||
processMetadataLock = threading.Lock()
|
processMetadataLock = threading.Lock()
|
||||||
# To keep track
|
# To keep track
|
||||||
|
@ -710,7 +715,9 @@ class LibrarySync(threading.Thread):
|
||||||
self.logMsg("Stop sent to all threads", 1)
|
self.logMsg("Stop sent to all threads", 1)
|
||||||
# Wait till threads are indeed dead
|
# Wait till threads are indeed dead
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
thread.join()
|
thread.join(15.0)
|
||||||
|
if thread.isAlive():
|
||||||
|
self.logMsg("Could not terminate thread", -1)
|
||||||
if dialog:
|
if dialog:
|
||||||
dialog.close()
|
dialog.close()
|
||||||
self.logMsg("=====================", 1)
|
self.logMsg("=====================", 1)
|
||||||
|
|
Loading…
Reference in a new issue