提交 ff4be822 编写于 作者: Y Yi Wang

Handle multiple processes trying to create the data home directory

上级 603fd43d
...@@ -27,13 +27,17 @@ __all__ = ['DATA_HOME', 'download', 'md5file', 'split', 'cluster_files_reader'] ...@@ -27,13 +27,17 @@ __all__ = ['DATA_HOME', 'download', 'md5file', 'split', 'cluster_files_reader']
DATA_HOME = os.path.expanduser('~/.cache/paddle/dataset') DATA_HOME = os.path.expanduser('~/.cache/paddle/dataset')
if not os.path.exists(DATA_HOME): # When running unit tests, there could be multiple processes that
try: # trying to create DATA_HOME directory simultaneously, so we cannot
os.makedirs(DATA_HOME) # use a if condition to check for the existence of the directory;
except OSError as exc: # instead, we use the filesystem as the synchronization mechanism by
if exc.errno != errno.EEXIST: # catching returned errors.
raise try:
pass os.makedirs(DATA_HOME)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise
pass
def md5file(fname): def md5file(fname):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册