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

Commit36cdfd3

Browse files
committed
Made improvements to assure test-cases don't leak file handles
At least leakage is considerably reduced.Additionally, a test-case was added which triggers failure if auto-disposalof resources wouldn't work.Fixesgitpython-developers#60
1 parentf4a49ff commit36cdfd3

File tree

7 files changed

+57
-6
lines changed

7 files changed

+57
-6
lines changed

‎.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ install:
2525
-git config --global user.email "travis@ci.com"
2626
-git config --global user.name "Travis Runner"
2727
script:
28+
# Make sure we limit open handles to see if we are leaking them
29+
-ulimit -n 64
30+
-ulimit -n
2831
-nosetests -v --with-coverage
2932
-flake8
3033
after_success:

‎git/cmd.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838

3939
__all__= ('Git', )
4040

41+
ifsys.platform!='win32':
42+
WindowsError=OSError
43+
4144

4245
# ==============================================================================
4346
## @name Utilities
@@ -203,11 +206,18 @@ def __init__(self, proc, args):
203206
self.args=args
204207

205208
def__del__(self):
206-
self.proc.stdout.close()
207-
self.proc.stderr.close()
209+
ifself.procisNone:
210+
return
211+
212+
proc=self.proc
213+
self.proc=None
214+
ifproc.stdin:
215+
proc.stdin.close()
216+
proc.stdout.close()
217+
proc.stderr.close()
208218

209219
# did the process finish already so we have a return code ?
210-
ifself.proc.poll()isnotNone:
220+
ifproc.poll()isnotNone:
211221
return
212222

213223
# can be that nothing really exists anymore ...
@@ -216,16 +226,16 @@ def __del__(self):
216226

217227
# try to kill it
218228
try:
219-
os.kill(self.proc.pid,2)# interrupt signal
220-
self.proc.wait()# ensure process goes away
229+
os.kill(proc.pid,2)# interrupt signal
230+
proc.wait()# ensure process goes away
221231
except (OSError,WindowsError):
222232
pass# ignore error when process already died
223233
exceptAttributeError:
224234
# try windows
225235
# for some reason, providing None for stdout/stderr still prints something. This is why
226236
# we simply use the shell and redirect to nul. Its slower than CreateProcess, question
227237
# is whether we really want to see all these messages. Its annoying no matter what.
228-
call(("TASKKILL /F /T /PID %s 2>nul 1>nul"%str(self.proc.pid)),shell=True)
238+
call(("TASKKILL /F /T /PID %s 2>nul 1>nul"%str(proc.pid)),shell=True)
229239
# END exception handling
230240

231241
def__getattr__(self,attr):

‎git/refs/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ def iter_entries(cls, stream):
204204
return
205205
yieldnew_entry(line.strip())
206206
# END endless loop
207+
stream.close()
207208

208209
@classmethod
209210
defentry_at(cls,filepath,index):

‎git/repo/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ def __init__(self, path=None, odbt=DefaultDBType):
168168
args.append(self.git)
169169
self.odb=odbt(*args)
170170

171+
def__del__(self):
172+
ifself.git:
173+
self.git.clear_cache()
174+
171175
def__eq__(self,rhs):
172176
ifisinstance(rhs,Repo):
173177
returnself.git_dir==rhs.git_dir

‎git/test/lib/helper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ def setUpClass(cls):
279279
"""
280280
cls.rorepo=Repo(GIT_REPO)
281281

282+
@classmethod
283+
deftearDownClass(cls):
284+
cls.rorepo.git.clear_cache()
285+
cls.rorepo.git=None
286+
282287
def_make_file(self,rela_path,data,repo=None):
283288
"""
284289
Create a file at the given path relative to our repository, filled

‎git/test/performance/lib.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ def setUp(self):
5959
self.gitrorepo=Repo(repo_path,odbt=GitCmdObjectDB)
6060
self.puregitrorepo=Repo(repo_path,odbt=GitDB)
6161

62+
deftearDown(self):
63+
self.gitrorepo.git.clear_cache()
64+
self.gitrorepo=None
65+
self.puregitrorepo.git.clear_cache()
66+
self.puregitrorepo=None
67+
6268

6369
classTestBigRepoRW(TestBigRepoR):
6470

@@ -78,7 +84,12 @@ def setUp(self):
7884
self.puregitrwrepo=Repo(dirname,odbt=GitDB)
7985

8086
deftearDown(self):
87+
super(TestBigRepoRW,self).tearDown()
8188
ifself.gitrwrepoisnotNone:
8289
shutil.rmtree(self.gitrwrepo.working_dir)
90+
self.gitrwrepo.git.clear_cache()
91+
self.gitrwrepo=None
92+
self.puregitrwrepo.git.clear_cache()
93+
self.puregitrwrepo=None
8394

8495
#} END base classes

‎git/test/test_repo.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,3 +656,20 @@ def test_git_file(self, rwrepo):
656656
open(git_file_path,'wb').write(('gitdir: %s\n'%real_path_abs).encode('ascii'))
657657
git_file_repo=Repo(rwrepo.working_tree_dir)
658658
assertos.path.abspath(git_file_repo.git_dir)==real_path_abs
659+
660+
deftest_file_handle_leaks(self):
661+
deflast_commit(repo,rev,path):
662+
commit=next(repo.iter_commits(rev,path,max_count=1))
663+
commit.tree[path]
664+
665+
# This is based on this comment
666+
# https://github.com/gitpython-developers/GitPython/issues/60#issuecomment-23558741
667+
# And we expect to set max handles to a low value, like 64
668+
# You should set ulimit -n X, see .travis.yml
669+
# The loops below would easily create 500 handles if these would leak (4 pipes + multiple mapped files)
670+
foriinrange(64):
671+
forrepo_typein (GitCmdObjectDB,GitDB):
672+
repo=Repo(self.rorepo.working_tree_dir,odbt=repo_type)
673+
last_commit(repo,'master','git/test/test_base.py')
674+
# end for each repository type
675+
# end for each iteration

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp