Rev 3795: During Transport.readv() close the file handle if we can. in http://bzr.arbash-meinel.com/branches/bzr/1.9-dev/readv_close
John Arbash Meinel
john at arbash-meinel.com
Sat Oct 25 01:30:12 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.9-dev/readv_close
------------------------------------------------------------
revno: 3795
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.
-------------- next part --------------
=== 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-25 00:30:07 +0000
@@ -661,6 +661,7 @@
"""
# We are going to iterate multiple times, we need a list
offsets = list(offsets)
+ remaining = len(offsets)
sorted_offsets = sorted(offsets)
# turn the list of offsets into a stack
@@ -688,6 +689,12 @@
# 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)
+ remaining -= 1
+ if remaining <= 0:
+ # Close the file handle as we are done yielding data.
+ close = getattr(fp, 'close', None)
+ if close is not None:
+ close()
yield cur_offset_and_size[0], this_data
cur_offset_and_size = offset_stack.next()
More information about the bazaar-commits
mailing list