This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Adam Dunlap
Recipients Adam Dunlap
Date 2018-11-08.20:08:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1541707708.76.0.788709270274.issue35192@psf.upfronthosting.co.za>
In-reply-to
Content
I have 2 processes (one C, one python) that are started at the same time and both need a certain directory tree to exist to continue, so both processes create the directory tree while ignoring errors about it already existing.

In the python process, I'm using pathlib's mkdir function (https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir) with parents=True, exist_ok=True, but this is sometimes throwing a FileExistsError. I don't expect this because the documentation says "If exist_ok is true, FileExistsError exceptions will be ignored (same behavior as the POSIX mkdir -p command), but only if the last path component is not an existing non-directory file." The last component is never a non-directory file.

I believe what is happening is that mkdir realizes that the parent doesn't exist, so it recursively tries to make the parent directory. However, when it recurses, it uses the default exists_ok value of False. Before the recursive call can make the parent directory, the other process makes the directory. This causes the inner call to throw a FileExistsError.

I believe the correct thing to do is to always pass True for exists_ok in the recursive call.
History
Date User Action Args
2018-11-08 20:08:28Adam Dunlapsetrecipients: + Adam Dunlap
2018-11-08 20:08:28Adam Dunlapsetmessageid: <1541707708.76.0.788709270274.issue35192@psf.upfronthosting.co.za>
2018-11-08 20:08:28Adam Dunlaplinkissue35192 messages
2018-11-08 20:08:28Adam Dunlapcreate