dont end download thread if one download fails
This commit is contained in:
parent
1e9a1ef4ef
commit
2e09464c4d
2 changed files with 34 additions and 26 deletions
|
@ -4,13 +4,13 @@ from __future__ import division
|
||||||
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import time
|
import time
|
||||||
import logging
|
|
||||||
|
|
||||||
import db
|
import db
|
||||||
import state
|
import state
|
||||||
import settings
|
import settings
|
||||||
import update
|
import update
|
||||||
|
|
||||||
|
import logging
|
||||||
logger = logging.getLogger('oml.downloads')
|
logger = logging.getLogger('oml.downloads')
|
||||||
|
|
||||||
class Downloads(Thread):
|
class Downloads(Thread):
|
||||||
|
|
58
oml/nodes.py
58
oml/nodes.py
|
@ -298,33 +298,41 @@ class Node(Thread):
|
||||||
t1 = datetime.utcnow()
|
t1 = datetime.utcnow()
|
||||||
logger.debug('download %s', url)
|
logger.debug('download %s', url)
|
||||||
self._opener.addheaders = zip(headers.keys(), headers.values())
|
self._opener.addheaders = zip(headers.keys(), headers.values())
|
||||||
r = self._opener.open(url, timeout=self.TIMEOUT*2)
|
try:
|
||||||
|
r = self._opener.open(url, timeout=self.TIMEOUT*2)
|
||||||
|
except:
|
||||||
|
logger.debug('openurl failed %s', url, exec_info=1)
|
||||||
|
return False
|
||||||
if r.getcode() == 200:
|
if r.getcode() == 200:
|
||||||
if r.headers.get('content-encoding', None) == 'gzip':
|
try:
|
||||||
content = gzip.GzipFile(fileobj=r).read()
|
if r.headers.get('content-encoding', None) == 'gzip':
|
||||||
else:
|
content = gzip.GzipFile(fileobj=r).read()
|
||||||
content = ''
|
else:
|
||||||
ct = datetime.utcnow()
|
content = ''
|
||||||
for chunk in iter(lambda: r.read(16*1024), ''):
|
ct = datetime.utcnow()
|
||||||
content += chunk
|
for chunk in iter(lambda: r.read(16*1024), ''):
|
||||||
if (datetime.utcnow() - ct).total_seconds() > 1:
|
content += chunk
|
||||||
ct = datetime.utcnow()
|
if (datetime.utcnow() - ct).total_seconds() > 1:
|
||||||
t = Transfer.get(item.id)
|
ct = datetime.utcnow()
|
||||||
t.progress = len(content) / item.info['size']
|
t = Transfer.get(item.id)
|
||||||
t.save()
|
t.progress = len(content) / item.info['size']
|
||||||
trigger_event('transfer', {
|
t.save()
|
||||||
'id': item.id, 'progress': t.progress
|
trigger_event('transfer', {
|
||||||
})
|
'id': item.id, 'progress': t.progress
|
||||||
'''
|
})
|
||||||
content = r.read()
|
'''
|
||||||
'''
|
content = r.read()
|
||||||
|
'''
|
||||||
|
|
||||||
t2 = datetime.utcnow()
|
t2 = datetime.utcnow()
|
||||||
duration = (t2-t1).total_seconds()
|
duration = (t2-t1).total_seconds()
|
||||||
if duration:
|
if duration:
|
||||||
self.download_speed = len(content) / duration
|
self.download_speed = len(content) / duration
|
||||||
logger.debug('SPEED %s', ox.format_bits(self.download_speed))
|
logger.debug('SPEED %s', ox.format_bits(self.download_speed))
|
||||||
return item.save_file(content)
|
return item.save_file(content)
|
||||||
|
except:
|
||||||
|
logger.debug('download failed %s', url, exec_info=1)
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
logger.debug('FAILED %s', url)
|
logger.debug('FAILED %s', url)
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in a new issue