From b6093450d2da894c64567f4c4b1cf239478fc943 Mon Sep 17 00:00:00 2001 From: Lawrence Mitchell Date: Fri, 9 Nov 2018 13:02:26 +0000 Subject: [PATCH] compilation: Fix race when creating output directories If multiple processes are running at the same time, they could race on output directory creation, fix this by just allowing the directories to exist. --- pyop2/compilation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyop2/compilation.py b/pyop2/compilation.py index f4b1d4e87..4b45c8b39 100644 --- a/pyop2/compilation.py +++ b/pyop2/compilation.py @@ -122,7 +122,7 @@ def compilation_comm(comm): import tempfile if comm.rank == 0: if not os.path.exists(configuration["cache_dir"]): - os.makedirs(configuration["cache_dir"]) + os.makedirs(configuration["cache_dir"], exist_ok=True) tmpname = tempfile.mkdtemp(prefix="rank-determination-", dir=configuration["cache_dir"]) else: @@ -236,7 +236,7 @@ def get_so(self, src, extension): srcfile = os.path.join(output, "src-rank%d.c" % self.comm.rank) if self.comm.rank == 0: if not os.path.exists(output): - os.makedirs(output) + os.makedirs(output, exist_ok=True) self.comm.barrier() with open(srcfile, "w") as f: f.write(src) @@ -250,7 +250,7 @@ def get_so(self, src, extension): if self.comm.rank == 0: # No need to do this on all ranks if not os.path.exists(cachedir): - os.makedirs(cachedir) + os.makedirs(cachedir, exist_ok=True) logfile = os.path.join(cachedir, "%s_p%d.log" % (basename, pid)) errfile = os.path.join(cachedir, "%s_p%d.err" % (basename, pid)) with progress(INFO, 'Compiling wrapper'):