summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-02 16:10:14 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2009-06-02 16:10:14 +0200
commite81214c6d448e4a53687aa4ac775ad883915c6a8 (patch)
treeed1e2cb541f9dfdb8f72f9360907d0556ad3570c
parentnew reconnect method, hard to test (diff)
downloadpyload-e81214c6d448e4a53687aa4ac775ad883915c6a8.tar.xz
changed reconnect method, still not working 100% correct
-rw-r--r--module/download_thread.py26
-rw-r--r--module/thread_list.py60
2 files changed, 46 insertions, 40 deletions
diff --git a/module/download_thread.py b/module/download_thread.py
index 80a1d4c30..62ac633ee 100644
--- a/module/download_thread.py
+++ b/module/download_thread.py
@@ -96,17 +96,17 @@ class Download_Thread(threading.Thread):
def download(self, pyfile):
status = pyfile.status
pyfile.prepareDownload()
- print "dl prepared", status.filename
+ print "dl prepared", status.filename
- rnd = random.randint(0,2)
- if rnd == 0:
- print status.filename, "want reconnect"
- status.want_reconnect = True
- status.waituntil = time() + 60
- else:
- status.waituntil = 0
- status.want_reconnect = False
- print status.filename, "doesnt want reconnect"
+ rnd = random.randint(0,1)
+ if rnd == 0:
+ print status.filename, "want reconnect"
+ status.want_reconnect = True
+ status.waituntil = time() + 60
+ else:
+ status.waituntil = 0
+ status.want_reconnect = False
+ print status.filename, "doesnt want reconnect"
if not status.exists:
@@ -116,15 +116,15 @@ class Download_Thread(threading.Thread):
reconnect = self.parent.init_reconnect()
if reconnect:
status.type = "reconnected"
- status.want_reconnect = False
+ status.want_reconnect = False
return False
- status.type = "waiting"
+ status.type = "waiting"
while (time() < status.waituntil):
if status.want_reconnect and self.parent.reconnecting:
status.type = "reconnected"
- status.want_reconnect = False
+ status.want_reconnect = False
return False
sleep(1)
diff --git a/module/thread_list.py b/module/thread_list.py
index 874317dc6..8941ba552 100644
--- a/module/thread_list.py
+++ b/module/thread_list.py
@@ -30,7 +30,7 @@ class Thread_List(object):
def __init__(self, parent):
self.parent = parent
self.threads = []
- self.max_threads = 2
+ self.max_threads = 3
self.py_load_files = [] # files in queque
self.f_relation = [0, 0]
self.lock = RLock()
@@ -65,20 +65,20 @@ class Thread_List(object):
def get_job(self):
# return job if suitable, otherwise send thread idle
-
- if self.reconnecting:
+
+ if self.reconnecting:
return None
- print "get new job"
self.init_reconnect()
- time.sleep(2)
+ time.sleep(1)
if self.pause:
return None
- self.lock.acquire()
+ self.lock.acquire()
+ print "get new job"
pyfile = None
for i in range(len(self.py_load_files)):
if not self.py_load_files[i].modul.__name__ in self.occ_plugins:
@@ -135,41 +135,47 @@ class Thread_List(object):
self.select_thread()
def init_reconnect(self):
- self.lock.acquire()
+ """initialise a reonnect"""
+ self.lock.acquire()
+
+ if self.check_reconnect():
+ print "time to reconnect"
- if self.check_reconnect():
-
- print "time to reconnect"
+ self.reconnecting = True
- self.reconnecting = True
+ self.reconnect()
- self.reconnect()
+ while self.check_reconnect():
+ time.sleep(0.5)
+ print "waiting for all downloads"
- self.reconnecting = False
+ self.reconnecting = False
self.lock.release()
return False
def check_reconnect(self):
- if not self.py_downloading:
- return False
+ """checks if all files want reconnect"""
+
+ if not self.py_downloading:
+ return False
- i = 0
- for obj in self.py_downloading:
- if obj.status.want_reconnect:
- i += 1
-
- if len(self.py_downloading) == i:
- return True
- else:
- return False
+ i = 0
+ for obj in self.py_downloading:
+ if obj.status.want_reconnect:
+ i += 1
+
+ if len(self.py_downloading) == i:
+ return True
+ else:
+ return False
def reconnect(self):
- print "imagine reconnect"
- time.sleep(10)
- return True
+ print "imagine reconnect"
+ time.sleep(5)
+ return True
reconn = subprocess.Popen(self.parent.config['reconnectMethod'])
reconn.wait()