mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 22:51:01 +01:00
Added a bit of extra protectedness in PeriodicFileDownloader._downloadFile.
This commit is contained in:
parent
332a1826d5
commit
8fc6502ed3
@ -199,7 +199,13 @@ class PeriodicFileDownloader(object):
|
|||||||
self.getFile(filename)
|
self.getFile(filename)
|
||||||
|
|
||||||
def _downloadFile(self, filename, url, f):
|
def _downloadFile(self, filename, url, f):
|
||||||
|
try:
|
||||||
|
try:
|
||||||
infd = urllib2.urlopen(url)
|
infd = urllib2.urlopen(url)
|
||||||
|
except IOError, e:
|
||||||
|
self.log.warning('Error downloading %s', url)
|
||||||
|
self.log.exception('Exception:')
|
||||||
|
return
|
||||||
newFilename = os.path.join(conf.dataDir, utils.mktemp())
|
newFilename = os.path.join(conf.dataDir, utils.mktemp())
|
||||||
outfd = file(newFilename, 'wb')
|
outfd = file(newFilename, 'wb')
|
||||||
start = time.time()
|
start = time.time()
|
||||||
@ -209,7 +215,8 @@ class PeriodicFileDownloader(object):
|
|||||||
s = infd.read(4096)
|
s = infd.read(4096)
|
||||||
infd.close()
|
infd.close()
|
||||||
outfd.close()
|
outfd.close()
|
||||||
self.log.info('Downloaded %s in %s seconds',filename,time.time()-start)
|
self.log.info('Downloaded %s in %s seconds',
|
||||||
|
filename, time.time()-start)
|
||||||
self.downloadedCounter[filename] += 1
|
self.downloadedCounter[filename] += 1
|
||||||
self.lastDownloaded[filename] = time.time()
|
self.lastDownloaded[filename] = time.time()
|
||||||
if f is None:
|
if f is None:
|
||||||
@ -223,7 +230,9 @@ class PeriodicFileDownloader(object):
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
f(newFilename)
|
f(newFilename)
|
||||||
total = time.time() - start
|
total = time.time() - start
|
||||||
self.log.info('Function ran on %s in %s seconds', filename, total)
|
self.log.info('Function ran on %s in %s seconds',
|
||||||
|
filename, total)
|
||||||
|
finally:
|
||||||
self.currentlyDownloading.remove(filename)
|
self.currentlyDownloading.remove(filename)
|
||||||
|
|
||||||
def getFile(self, filename):
|
def getFile(self, filename):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user