minor update

This commit is contained in:
Miroslav Stampar 2011-12-20 15:01:27 +00:00
parent d3a428c9c8
commit 8bfff4a28e

View File

@ -232,9 +232,8 @@ class BigArray(list):
def pop(self): def pop(self):
if len(self.chunks[-1]) < 1: if len(self.chunks[-1]) < 1:
self.chunks.pop() self.chunks.pop()
fp = open(self.chunks[-1], 'rb') with open(self.chunks[-1], 'rb') as fp:
self.chunks[-1] = pickle.load(fp) self.chunks[-1] = pickle.load(fp)
fp.close()
return self.chunks[-1].pop() return self.chunks[-1].pop()
def index(self, value): def index(self, value):
@ -247,9 +246,8 @@ class BigArray(list):
handle, filename = tempfile.mkstemp() handle, filename = tempfile.mkstemp()
self.filenames.add(filename) self.filenames.add(filename)
os.close(handle) os.close(handle)
fp = open(filename, 'w+b') with open(filename, 'w+b') as fp:
pickle.dump(value, fp) pickle.dump(value, fp)
fp.close()
return filename return filename
def _checkcache(self, index): def _checkcache(self, index):
@ -257,9 +255,8 @@ class BigArray(list):
filename = self._dump(self.cache[1]) filename = self._dump(self.cache[1])
self.chunks[self.cache[0]] = filename self.chunks[self.cache[0]] = filename
if not (self.cache and self.cache[0] == index): if not (self.cache and self.cache[0] == index):
fp = open(self.chunks[index], 'rb') with open(self.chunks[index], 'rb') as fp:
self.cache = [index, pickle.load(fp), False] self.cache = (index, pickle.load(fp), False)
fp.close()
def __getitem__(self, y): def __getitem__(self, y):
index = y / BIGARRAY_CHUNK_LENGTH index = y / BIGARRAY_CHUNK_LENGTH
@ -2773,7 +2770,7 @@ def intersect(valueA, valueB, lowerCase=False):
def cpuThrottle(value): def cpuThrottle(value):
""" """
Does a CPU throttling for a lesser CPU consumption Does a CPU throttling for lesser CPU consumption
""" """
delay = 0.00001 * (value ** 2) delay = 0.00001 * (value ** 2)