提交 1db1fa6b authored 作者: Ian Goodfellow's avatar Ian Goodfellow

do race-able check before making directory, to reduce # of directory creation attempts

上级 92a178d3
...@@ -30,20 +30,19 @@ try: ...@@ -30,20 +30,19 @@ try:
# compile_str()) but if another lazylinker_ext does exist then it will be # compile_str()) but if another lazylinker_ext does exist then it will be
# imported and compile_str won't get called at all. # imported and compile_str won't get called at all.
location = os.path.join(config.compiledir, 'lazylinker_ext') location = os.path.join(config.compiledir, 'lazylinker_ext')
try:
# Try to make the location
os.mkdir(location)
except OSError, e:
# If we get an error, verify that the error was # 17, the path already exists,
# and that it is a directory
# Note: we can't check if it exists before making it, because we are not holding
# the lock right now, so we could race another process and get error 17 if we lose
# the race
assert 'Errno 17' in str(e)
assert os.path.isdir(location)
if not os.path.exists(location): if not os.path.exists(location):
os.mkdir(location) try:
# Try to make the location
os.mkdir(location)
except OSError, e:
# If we get an error, verify that the error was # 17, the path already exists,
# and that it is a directory
# Note: we can't check if it exists before making it, because we are not holding
# the lock right now, so we could race another process and get error 17 if we lose
# the race
assert 'Errno 17' in str(e)
assert os.path.isdir(location)
if not os.path.exists(os.path.join(location, '__init__.py')): if not os.path.exists(os.path.join(location, '__init__.py')):
file(os.path.join(location, '__init__.py'), 'w').close() file(os.path.join(location, '__init__.py'), 'w').close()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论