diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-05-22 00:19:04 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2009-05-22 00:19:04 +0200 |
commit | 3d34e6052db68ff482aa1aca65d512ddf40c310e (patch) | |
tree | 3b96511d5f10a9620f0f565eafe51eb398365365 | |
parent | was wir nicht brauchen auskommentiert, host überprüfung verlagert (diff) | |
download | pyload-3d34e6052db68ff482aa1aca65d512ddf40c310e.tar.xz |
remove queue from thread list and implemented own method to get suited
job for a thread
-rw-r--r-- | Core.py | 4 | ||||
-rw-r--r-- | module/Py_Load_File.py | 5 | ||||
-rw-r--r-- | module/download_thread.py | 28 | ||||
-rw-r--r-- | module/thread_list.py | 44 |
4 files changed, 52 insertions, 29 deletions
@@ -223,9 +223,9 @@ class Core(object): return True def _test_print_status(self): - if len(self.thread_list.py_load_files)>0: + if len(self.thread_list.py_downloading)>0: - for pyfile in self.thread_list.py_load_files: + for pyfile in self.thread_list.py_downloading: if pyfile.status.type == 'downloading': print "Speed" ,pyfile.status.get_speed() print "ETA" , pyfile.status.get_ETA() diff --git a/module/Py_Load_File.py b/module/Py_Load_File.py index 96936e4af..8fb45c079 100644 --- a/module/Py_Load_File.py +++ b/module/Py_Load_File.py @@ -1,4 +1,3 @@ -# -*- coding: cp1252 -*- from download_thread import Status import re @@ -11,7 +10,7 @@ class PyLoadFile: self.url = url self.filename = "filename" self.download_folder = "" - self.modul = __import__(self._get_my_plugin()) + self.modul = __import__(self._get_my_plugin()) #maybe replace to prepare download pluginClass = getattr(self.modul, self.modul.__name__) self.plugin = pluginClass(self) self.download_folder = "" @@ -22,7 +21,7 @@ class PyLoadFile: """ searches the right plugin for an url """ for plugin, plugin_pattern in self.parent.plugins_avaible.items(): - if re.match(plugin_pattern, self.url) != None: #guckt ob übergebende url auf muster des plugins passt + if re.match(plugin_pattern, self.url) != None: return plugin #logger: kein plugin gefunden # was soll passieren wenn nichts gefunden wird?!? return None diff --git a/module/download_thread.py b/module/download_thread.py index 896553a1c..e8dbf64c0 100644 --- a/module/download_thread.py +++ b/module/download_thread.py @@ -80,10 +80,11 @@ class Download_Thread(threading.Thread): def run(self): while (not self.shutdown): - if not self.parent.download_queue.empty(): - self.loadedPyFile = self.parent.getJob() - self.download(self.loadedPyFile) - + if self.parent.py_load_files: + self.loadedPyFile = self.parent.get_job() + if self.loadedPyFile: + self.download(self.loadedPyFile) + sleep(0.5) if self.shutdown: sleep(1) self.parent.remove_thread(self) @@ -104,21 +105,18 @@ class Download_Thread(threading.Thread): status.type = "waiting" sleep(1) #eventuell auf genaue zeit warten - #missing wenn datei nicht auf server vorhanden - #if type=="check": - #return params - #if type in 'missing': - #self.status = "missing" - #print "Datei auf Server nicht vorhanden: " + params - ##im logger eintragen das datei auf server nicht vorhanden ist - #warning("Datei auf Server nicht voblocks_readrhanden: " + url) - print "going to download" status.type = "downloading" print status.url , status.filename + + try: + pyfile.plugin.req.download(status.url, pyfile.download_folder + "/" + status.filename) + status.type = "finished" + except: + status.type = "failed" + + self.parent.job_finished(pyfile) - pyfile.plugin.req.download(status.url, pyfile.download_folder + "/" + status.filename) - status.type = "finished" #startet downloader #urllib.urlretrieve(status.url, pyfile.download_folder + "/" + status.filename, status) #self.shutdown = True diff --git a/module/thread_list.py b/module/thread_list.py index 2a5dbe6f6..5f1710368 100644 --- a/module/thread_list.py +++ b/module/thread_list.py @@ -19,7 +19,7 @@ ### #python from Queue import Queue - +from threading import Lock #my from download_thread import Download_Thread @@ -28,11 +28,14 @@ class Thread_List(object): self.parent = parent self.threads = [] self.max_threads = 3 - self.py_load_files = [] + self.py_load_files = [] # files in queque self.download_queue = Queue() - self.status_queue = Queue() + #self.status_queue = Queue() self.f_relation = [0,0] - + self.lock = Lock() + self.py_downloading = [] # files downloading + self.occ_plugins = [] #occupied plugins + def create_thread(self): """ creates thread for Py_Load_File and append thread to self.threads """ @@ -56,11 +59,34 @@ class Thread_List(object): status = self.status_queue.get() self.py_load_files[status.id].status = status - def getJob(self): - # nur wenn auch geladen werden soll, ansonsten thread in leerlauf schicken - if True: - return self.download_queue.get() - + def get_job(self): + # return job if suitable, otherwise send thread idle + self.lock.acquire() + + pyfile = None + + for i in range(0,len(self.py_load_files)): + if not self.py_load_files[i].modul.__name__ in self.occ_plugins: + pyfile = self.py_load_files.pop(i) + + if pyfile: + self.py_downloading.append(pyfile) + self.occ_plugins.append(pyfile.modul.__name__) + + self.lock.release() + return pyfile + + def job_finish(self, pyfile): + self.lock.acquire() + + self.occ_plugins.remove(pyfile.modul.__name__) + self.py_downloading.remove(pyfile) + + #remove from list, logging etc + + self.lock.release() + return True + def extend_py_load_files(self): pass |