X Tutup
Skip to content

FIX: subtle race condition in cbook.mkdirs#5224

Merged
jenshnielsen merged 3 commits intomatplotlib:v1.5.xfrom
tacaswell:mnt_mkdirs_race
Oct 13, 2015
Merged

FIX: subtle race condition in cbook.mkdirs#5224
jenshnielsen merged 3 commits intomatplotlib:v1.5.xfrom
tacaswell:mnt_mkdirs_race

Conversation

@tacaswell
Copy link
Copy Markdown
Member

attn @timj

@tacaswell tacaswell modified the milestones: next point release (1.5.0), next bug fix release (2.0.1) Oct 12, 2015
@tacaswell
Copy link
Copy Markdown
Member Author

closes #5225

@timj
Copy link
Copy Markdown

timj commented Oct 12, 2015

Thanks. Looks good to me except that I wonder why the Python2.7 code calls makedirs when it's not really using any of the functionality of that routine and may as well be using mkdir for each path component.

@tacaswell
Copy link
Copy Markdown
Member Author

Good point, simplified.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit): I know it's equivalent, but I think I'd prefer to see the Python 2 stuff in an else clause so it's more obvious it only runs on Python 2.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. That make lots of sense and will make ripping out the LPY stuff easier.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know that this works with multiple processes? I thought the whole point of exist_ok in Python3 was to handle the case of the directory pre-existing, and I thought the initial attempt at rewriting the code to look at each leaf separately was to work around the multi-process problem. Isn't this code now back to how it was before the change to protect from multiple processes attempting to create the directory? My previous comment was that os.makedirs looked like it should just be os.mkdir as the code was only ever creating a directory at a time.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have now delegated that problem down to cpython?

@timj
Copy link
Copy Markdown

timj commented Oct 12, 2015

The reimplementation of makedirs seemed to appear in 529c88e but the commit message doesn't really tell me anything about why that change was made.

@timj
Copy link
Copy Markdown

timj commented Oct 12, 2015

@tacaswell for some reason I can't see the comment I just got in email on Github. I think I'm saying that CPython 2.7 may not handle the multi-process race condition properly and simply calling os.makedirs may not be the real fix. I'm not sure if that's the case though as I assume the code in 529c88e was added for a reason. Maybe Python 2.7 doesn't have the problem (the code was put in to matplotlib in 2008)?

@tacaswell
Copy link
Copy Markdown
Member Author

https://github.com/python/cpython/blob/master/Lib/os.py#L216 <- current implementation of os.makedirs which looks like it handles things properly.

https://github.com/python/cpython/blob/2.7/Lib/os.py#L136 <- implementation for 2.7 which also looks like it handles this race condition properly.

It looks like 2.5 (https://github.com/python/cpython/blob/2.5/Lib/os.py#L150) is where that checking first shows up (2.4: https://github.com/python/cpython/blob/2.4/Lib/os.py#L143)

you have to click the 'show outdated diff' link up the page a bit to see the comment.

@timj
Copy link
Copy Markdown

timj commented Oct 12, 2015

Thanks. I'm happy now 😄 👍

jenshnielsen added a commit that referenced this pull request Oct 13, 2015
FIX: subtle race condition in cbook.mkdirs
@jenshnielsen jenshnielsen merged commit b518616 into matplotlib:v1.5.x Oct 13, 2015
@tacaswell tacaswell deleted the mnt_mkdirs_race branch October 29, 2015 16:08
@QuLogic QuLogic modified the milestones: v1.5.0, next bug fix release (2.0.1) Nov 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

X Tutup