Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd68ffc3

Browse files
committed
Closing file handles/streams
1 parentad715a0 commitd68ffc3

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

‎git/cmd.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ def execute(self, command,
382382
finally:
383383
proc.stdout.close()
384384
proc.stderr.close()
385+
ifproc.stdin:
386+
proc.stdin.close()
387+
proc.poll()
388+
ifproc.returncodeisNone:
389+
proc.terminate()
385390

386391
ifself.GIT_PYTHON_TRACE=='full':
387392
cmdstr=" ".join(command)

‎git/objects/commit.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -350,24 +350,31 @@ def _iter_from_process_or_stream(cls, odb, proc_or_stream):
350350
:param proc: git-rev-list process instance - one sha per line
351351
:return: iterator returning Commit objects"""
352352
stream=proc_or_stream
353+
close_std_err=False
353354
ifnothasattr(stream,'readline'):
354355
stream=proc_or_stream.stdout
356+
close_std_err=True
355357

356358
readline=stream.readline
357-
whileTrue:
358-
line=readline()
359-
ifnotline:
360-
break
361-
hexsha=line.strip()
362-
iflen(hexsha)>40:
363-
# split additional information, as returned by bisect for instance
364-
hexsha,rest=line.split(None,1)
365-
# END handle extra info
366-
367-
assertlen(hexsha)==40,"Invalid line: %s"%hexsha
368-
yieldcls(odb,hex_to_bin(hexsha))
369-
# END for each line in stream
370-
359+
try:
360+
whileTrue:
361+
line=readline()
362+
ifnotline:
363+
break
364+
hexsha=line.strip()
365+
iflen(hexsha)>40:
366+
# split additional information, as returned by bisect for instance
367+
hexsha,rest=line.split(None,1)
368+
# END handle extra info
369+
370+
assertlen(hexsha)==40,"Invalid line: %s"%hexsha
371+
yieldcls(odb,hex_to_bin(hexsha))
372+
# END for each line in stream
373+
finally:
374+
stream.close()
375+
ifclose_std_err:
376+
proc_or_stream.stderr.close()
377+
371378
#{ Serializable Implementation
372379

373380
def_serialize(self,stream):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp