diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2014-01-19 22:07:30 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2014-01-19 22:07:30 +0100 |
commit | 64570fa1697458705a94ae57af542af920cf0054 (patch) | |
tree | 41b7ed3a614bcf2dafced869f1b9c55858453783 | |
parent | better log message (diff) | |
download | pyload-64570fa1697458705a94ae57af542af920cf0054.tar.xz |
fixes for download scheduler
-rw-r--r-- | pyload/DownloadManager.py | 13 | ||||
-rw-r--r-- | pyload/api/FileApi.py | 1 | ||||
-rw-r--r-- | pyload/datatypes/PyFile.py | 18 | ||||
-rw-r--r-- | pyload/plugins/Hoster.py | 1 | ||||
-rw-r--r-- | pyload/threads/DownloadThread.py | 13 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/dashboard/selectionView.js | 2 |
6 files changed, 26 insertions, 22 deletions
diff --git a/pyload/DownloadManager.py b/pyload/DownloadManager.py index 2d12088b5..0c3294752 100644 --- a/pyload/DownloadManager.py +++ b/pyload/DownloadManager.py @@ -65,6 +65,8 @@ class DownloadManager: """ Switch thread from working to free state """ # only download threads will be re-used if isinstance(thread, DownloadThread): + # clean local var + thread.active = None self.working.remove(thread) self.free.append(thread) thread.isWorking.clear() @@ -76,8 +78,7 @@ class DownloadManager: """ Removes a thread from all lists """ if thread in self.free: self.free.remove(thread) - - if thread in self.working: + elif thread in self.working: self.working.remove(thread) @lock @@ -89,7 +90,7 @@ class DownloadManager: else: thread = DownloadThread(self) - thread.put(PyFile.fromInfoData(self.core.files, info)) + thread.put(self.core.files.getFile(info.fid)) # wait until it picked up the task thread.isWorking.wait() @@ -190,6 +191,8 @@ class DownloadManager: # we know exactly the number of remaining jobs # or only can start one job if limit is not known to_schedule = slots[plugin] if plugin in slots else 1 + # -1 means no limit + to_schedule = len(jobs) if to_schedule == -1 else to_schedule # start all chosen jobs for job in self.chooseJobs(jobs, to_schedule): # if the job was started the limit will be reduced @@ -216,7 +219,7 @@ class DownloadManager: if plugin == "hoster": # this job can't be started - if limit == 0: + if limit <= 0: return False self.startDownloadThread(info) @@ -284,7 +287,7 @@ class DownloadManager: @read_lock def wantReconnect(self): """ number of downloads that are waiting for reconnect """ - active = [x.active.plugin.wantReconnect and x.active.plugin.waiting for x in self.working] + active = [x.active.hasPlugin() and x.active.plugin.wantReconnect and x.active.plugin.waiting for x in self.working] return active.count(True) @read_lock diff --git a/pyload/api/FileApi.py b/pyload/api/FileApi.py index cebfb78d6..0f389043d 100644 --- a/pyload/api/FileApi.py +++ b/pyload/api/FileApi.py @@ -13,6 +13,7 @@ class FileApi(ApiComponent): def checkResult(self, info): """ Internal method to verify result and owner """ + #TODO: shared? return info and (not self.primaryUID or info.owner == self.primaryUID) @RequirePerm(Permission.All) diff --git a/pyload/datatypes/PyFile.py b/pyload/datatypes/PyFile.py index 720b97cda..8f33b09fd 100644 --- a/pyload/datatypes/PyFile.py +++ b/pyload/datatypes/PyFile.py @@ -151,7 +151,7 @@ class PyFile(object): @read_lock def hasPlugin(self): """Thread safe way to determine this file has initialized plugin attribute""" - return hasattr(self, "plugin") and self.plugin + return self.plugin is not None def package(self): """ return package instance""" @@ -182,9 +182,9 @@ class PyFile(object): @lock def release(self): """sync and remove from cache""" - if hasattr(self, "plugin") and self.plugin: + if self.plugin is not None: self.plugin.clean() - del self.plugin + self.plugin = None self.m.releaseFile(self.fid) @@ -202,30 +202,28 @@ class PyFile(object): def move(self, pid): pass - @read_lock def abortDownload(self): """abort pyfile if possible""" # TODO: abort timeout, currently dead locks while self.fid in self.m.core.dlm.processingIds(): + + self.lock.acquire(shared=True) self.abort = True if self.plugin and self.plugin.req: self.plugin.req.abort() if self.plugin.dl: self.plugin.dl.abort() + self.lock.release() - sleep(0.1) + sleep(0.5) self.abort = False - if self.plugin: - self.plugin.req.abort() - if self.plugin.dl: - self.plugin.dl.abort() - self.release() def finishIfDone(self): """set status to finish and release file if every thread is finished with it""" + # TODO: this is wrong now, it should check if addons are using it if self.id in self.m.core.dlm.processingIds(): return False diff --git a/pyload/plugins/Hoster.py b/pyload/plugins/Hoster.py index f63b83f5f..bbdb993de 100644 --- a/pyload/plugins/Hoster.py +++ b/pyload/plugins/Hoster.py @@ -206,7 +206,6 @@ class Hoster(Base): while self.pyfile.waitUntil > time(): self.thread.m.reconnecting.wait(2) - self.checkAbort() if self.thread.m.reconnecting.isSet(): self.waiting = False diff --git a/pyload/threads/DownloadThread.py b/pyload/threads/DownloadThread.py index 3ee9466b8..6ec102c52 100644 --- a/pyload/threads/DownloadThread.py +++ b/pyload/threads/DownloadThread.py @@ -148,15 +148,16 @@ class DownloadThread(BaseThread): pyfile.waitUntil = wait pyfile.setStatus("waiting") while time() < wait: - sleep(1) + sleep(0.5) + if pyfile.abort: break if pyfile.abort: self.log.info(_("Download aborted: %s") % pyfile.name) pyfile.setStatus("aborted") - - self.clean(pyfile) + # don't clean, aborting function does this itself + # self.clean(pyfile) else: self.queue.put(pyfile) @@ -215,7 +216,10 @@ class DownloadThread(BaseThread): exc_clear() # manager could still be waiting for it self.isWorking.set() - self.m.done(self) + + # only done when job was not put back + if self.queue.empty(): + self.m.done(self) #pyfile.plugin.req.clean() @@ -233,7 +237,6 @@ class DownloadThread(BaseThread): def clean(self, pyfile): """ set thread inactive and release pyfile """ - self.active = False pyfile.release() def stop(self): diff --git a/pyload/web/app/scripts/views/dashboard/selectionView.js b/pyload/web/app/scripts/views/dashboard/selectionView.js index 25b7998df..866eb1367 100644 --- a/pyload/web/app/scripts/views/dashboard/selectionView.js +++ b/pyload/web/app/scripts/views/dashboard/selectionView.js @@ -118,7 +118,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/dashboard/select'], }); if (fids.length > 0) - $.ajax(App.apiRequest('deleteFiles', {fids: fids})); + $.ajax(App.apiRequest('removeFiles', {fids: fids})); this.deselect(); }, this); |