diff --git a/news/3257.bugfix.rst b/news/3257.bugfix.rst new file mode 100644 index 0000000000..c816c93a8c --- /dev/null +++ b/news/3257.bugfix.rst @@ -0,0 +1 @@ +Fixed an issue where pipenv could crash when multiple pipenv processes attempted to create the same directory. diff --git a/pipenv/utils.py b/pipenv/utils.py index 22837d264e..84a4c105f0 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -832,8 +832,18 @@ def mkdir_p(newdir): if head and not os.path.isdir(head): mkdir_p(head) if tail: - os.mkdir(newdir) - + # Even though we've checked that the directory doesn't exist above, it might exist + # now if some other process has created it between now and the time we checked it. + try: + os.mkdir(newdir) + except OSError as exn: + # If we failed because the directory does exist, that's not a problem - + # that's what we were trying to do anyway. Only re-raise the exception + # if we failed for some other reason. + if exn.errno != errno.EEXIST: + raise + + def is_required_version(version, specified_version): """Check to see if there's a hard requirement for version