Skip to content

Commit

Permalink
Fix race condition when creating build dir (pytorch#30956)
Browse files Browse the repository at this point in the history
Summary:
The original `check-and-act` style can raise `FileExistsError` when multiple processes are jit-compiling the extension on the same node.
Pull Request resolved: pytorch#30956

Differential Revision: D19262570

Pulled By: ezyang

fbshipit-source-id: bb18c72e42648770b47f9378ac7c3929c3c03efc
  • Loading branch information
Stonesjtu authored and facebook-github-bot committed Jan 3, 2020
1 parent f56c59e commit 8c425dd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions torch/utils/cpp_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,13 @@ def _get_build_directory(name, verbose):
root_extensions_directory))

build_directory = os.path.join(root_extensions_directory, name)
if not os.path.exists(build_directory):
try:
os.makedirs(build_directory)
if verbose:
print('Creating extension directory {}...'.format(build_directory))
# This is like mkdir -p, i.e. will also create parent directories.
os.makedirs(build_directory)
except FileExistsError:
if verbose:
print('Using existing directory {}...'.format(build_directory))

return build_directory

Expand Down

0 comments on commit 8c425dd

Please sign in to comment.