Rev 3800: (jam) Transport._seek_and_readv() closes the fp before yielding the in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Oct 27 19:13:04 GMT 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3800
revision-id: pqm at pqm.ubuntu.com-20081027191300-cmrcjgft9wa2tddi
parent: pqm at pqm.ubuntu.com-20081027100754-ilnqmlvshjrw6itv
parent: john at arbash-meinel.com-20081027153029-ngnirc0efh3ulth6
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2008-10-27 19:13:00 +0000
message:
  (jam) Transport._seek_and_readv() closes the fp before yielding the
  	last bit of data.
modified:
  bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
    ------------------------------------------------------------
    revno: 3794.2.2
    revision-id: john at arbash-meinel.com-20081027153029-ngnirc0efh3ulth6
    parent: john at arbash-meinel.com-20081025003007-5xam89uv2d1b2pdb
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: readv_close
    timestamp: Mon 2008-10-27 10:30:29 -0500
    message:
      Instead of counting the remaining offsets, trap the offset exception
      This should give the same result, but it means one less thing to keep track of.
      Also, make fp.close() a required attribute, rather than optional.
    modified:
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
    ------------------------------------------------------------
    revno: 3794.2.1
    revision-id: john at arbash-meinel.com-20081025003007-5xam89uv2d1b2pdb
    parent: pqm at pqm.ubuntu.com-20081024113829-9geq0uavium22ho6
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: readv_close
    timestamp: Fri 2008-10-24 19:30:07 -0500
    message:
      During Transport.readv() close the file handle if we can.
      
      This helps reduce open file handles, especially on Windows where it prevents
      us from doing other things with the file.
    modified:
      bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2008-10-06 06:34:36 +0000
+++ b/bzrlib/transport/__init__.py	2008-10-27 15:30:29 +0000
@@ -688,8 +688,21 @@
             # Now that we've read some data, see if we can yield anything back
             while cur_offset_and_size in data_map:
                 this_data = data_map.pop(cur_offset_and_size)
-                yield cur_offset_and_size[0], this_data
-                cur_offset_and_size = offset_stack.next()
+                this_offset = cur_offset_and_size[0]
+                try:
+                    cur_offset_and_size = offset_stack.next()
+                except StopIteration:
+                    # Close the file handle as there will be no more data
+                    # The handle would normally be cleaned up as this code goes
+                    # out of scope, but as we are a generator, not all code
+                    # will re-enter once we have consumed all the expected
+                    # data. For example:
+                    #   zip(range(len(requests)), readv(foo, requests))
+                    # Will stop because the range is done, and not run the
+                    # cleanup code for the readv().
+                    fp.close()
+                    cur_offset_and_size = None
+                yield this_offset, this_data
 
     def _sort_expand_and_combine(self, offsets, upper_limit):
         """Helper for readv.




More information about the bazaar-commits mailing list