[Zodb-checkins] SVN: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob. - We really rely on the users to close the file handles correctly.

Christian Theune ct at gocept.com
Thu Mar 24 17:26:34 EST 2005


Log message for revision 29674:
   - We really rely on the users to close the file handles correctly.
   - I made the IStreamIterator not gently close itself, but rely on e.g. Medusa
     closing it.
   - The tests now document the behaviour that a user should close the file handles.
  

Changed:
  U   ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py
  U   ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.txt

-=-
Modified: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py
===================================================================
--- ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py	2005-03-24 22:15:53 UTC (rev 29673)
+++ ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.py	2005-03-24 22:26:33 UTC (rev 29674)
@@ -190,8 +190,6 @@
     def next(self):
         data = self.read(self.streamsize)
         if not data:
-            if self.blob is not None:
-                self.blob._rc_decref(self.mode)
             raise StopIteration
         return data
 

Modified: ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.txt
===================================================================
--- ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.txt	2005-03-24 22:15:53 UTC (rev 29673)
+++ ZODB/branches/ctheune-blobsupport/src/ZODB/Blobs/Blob.txt	2005-03-24 22:26:33 UTC (rev 29674)
@@ -58,7 +58,7 @@
     >>> f3.read()
     'Hi, Blob!'
 
-But we can't  open it for writing, while it is opened for reading:
+But we can't open it for writing, while it is opened for reading:
 
     >>> myblob.open("a")
     Traceback (most recent call last):
@@ -78,9 +78,28 @@
 
 Now we can read it:
 
+    >>> f4a = myblob.open("r")
+    >>> f4a.read()
+    'Hi, Blob!\nBlob is fine.'
+    >>> f4a.close()
+
+Please, always remember closing an opened blob, otherwise you might get
+blocked later on. Therefore you should avoid using the result of open()
+without binding it to a name:
+
     >>> myblob.open("r").read()
     'Hi, Blob!\nBlob is fine.'
+    >>> f4b = myblob.open("a")
+    Traceback (most recent call last):
+        ...
+    BlobError: Already opened for reading.
+    
+To clean that up, we have to commit or abort the current transaction, so the reference
+counters for opened blob files get to a valid state again:
 
+    >>> import transaction
+    >>> transaction.commit()
+
 We can read lines out of the blob too:
 
     >>> f5 = myblob.open("r")



More information about the Zodb-checkins mailing list