[Checkins] SVN: z3c.extfile/trunk/src/z3c/extfile/hashdir.py
readfile only opens each file once per thread,
this should prevent bus errors on huge load
Bernd Dorn
bernd.dorn at fhv.at
Wed Sep 13 14:08:09 EDT 2006
Log message for revision 70155:
readfile only opens each file once per thread, this should prevent bus errors on huge load
Changed:
U z3c.extfile/trunk/src/z3c/extfile/hashdir.py
-=-
Modified: z3c.extfile/trunk/src/z3c/extfile/hashdir.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/hashdir.py 2006-09-13 16:17:04 UTC (rev 70154)
+++ z3c.extfile/trunk/src/z3c/extfile/hashdir.py 2006-09-13 18:08:09 UTC (rev 70155)
@@ -7,6 +7,7 @@
import interfaces
from zope import interface
from persistent import Persistent
+from zope import thread
class HashDir(Persistent):
@@ -71,6 +72,7 @@
def open(self, digest):
return ReadFile(self.getPath(digest))
+openFiles = thread.local()
class ReadFile(object):
@@ -80,16 +82,19 @@
self.name = name
self.digest = os.path.split(self.name)[1]
self.bufsize=bufsize
- self._v_file = None
self._v_len = None
@property
def _file(self):
- if self._v_file is not None:
- if not self._v_file.closed:
- return self._v_file
- self._v_file = file(self.name, 'rb', self.bufsize)
- return self._v_file
+ if hasattr(openFiles, self.digest):
+ f = getattr(openFiles, self.digest)
+ if f.closed:
+ delattr(openFiles, self.digest)
+ else:
+ return f
+ f = file(self.name, 'rb', self.bufsize)
+ setattr(openFiles, self.digest, f)
+ return f
def __len__(self):
if self._v_len is None:
@@ -116,10 +121,11 @@
def close(self):
"""see file.close"""
- if self._v_file is not None:
- if not self._v_file.closed:
- return self._v_file.close()
- self._v_file = None
+ if hasattr(openFiles, self.digest):
+ f = getattr(openFiles, self.digest)
+ if not f.closed:
+ f.close()
+ delattr(openFiles, self.digest)
def fileno(self):
return self._file.fileno()
More information about the Checkins
mailing list