mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927)
This commit is contained in:
parent
afbb7a371f
commit
172bb39452
27 changed files with 249 additions and 259 deletions
|
@ -85,9 +85,7 @@ def read(fileiter, pat, whilematch):
|
|||
else:
|
||||
break
|
||||
|
||||
def combine(fname):
|
||||
f = open(fname)
|
||||
|
||||
def combinefile(f):
|
||||
fi = iter(f)
|
||||
|
||||
for line in read(fi, re.compile(r'^Remaining objects:$'), False):
|
||||
|
@ -121,8 +119,11 @@ def combine(fname):
|
|||
print('[%s->%s]' % (addr2rc[addr], rc), end=' ')
|
||||
print(guts, addr2guts[addr])
|
||||
|
||||
f.close()
|
||||
print("%d objects before, %d after" % (before, after))
|
||||
|
||||
def combine(fname):
|
||||
with open(fname) as f:
|
||||
combinefile(f)
|
||||
|
||||
if __name__ == '__main__':
|
||||
combine(sys.argv[1])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue