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.

Title: macostools.mkdirs: not thread-safe
Type: Stage:
Components: macOS Versions:
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jackjansen Nosy List: bob.ippolito, jackjansen, jneb, jvr, ronaldoussoren
Priority: normal Keywords:

Created on 2005-02-23 13:26 by jneb, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg60677 - (view) Author: Jurjen N.E. Bos (jneb) * Date: 2005-02-23 13:26
Here is an easily fixable semi-bug in macostools:
When two threads are creating the same directory structure, one 
of them will fail as soon as the other thread made a directory.
This is trivially fixable by ignoring the error, but I'm not sure if it is 
worth it, like this:

def mkdirs(dst):
    """Make directories leading to 'dst' if they don't exist yet"""
    if dst == '' or os.path.exists(dst):
    head, tail = os.path.split(dst)
    if os.sep == ':' and not ':' in head:
        head = head + ':'
    try: os.mkdir(dst, 0777)
    except OSError, err:
	if err.errno==17: #file exists
		#someone else has created the directory in the 
meantime. That's fine with me!
	else: raise
- Jurjen
msg60678 - (view) Author: Just van Rossum (jvr) * (Python triager) Date: 2005-03-01 08:40
Logged In: YES 

Hm, macostools.mkdirs() also isn't portable: it only works on OS9 
MacPython. Why don't you use os.makedirs() instead? (Which appears to 
have the same threads issue, though.)
msg60679 - (view) Author: Just van Rossum (jvr) * (Python triager) Date: 2005-03-01 08:49
Logged In: YES 

Oops, disregard that portability remark, it does work correctly in non-OS9 
Python as well. I _think_ macostools.mkdirs() predates os.makedirs(), it's 
probably best considered deprecated.
msg60680 - (view) Author: Bob Ippolito (bob.ippolito) * (Python committer) Date: 2006-07-15 17:04
Logged In: YES 

Most Python functions aren't intended to be thread-safe, this is what locks are 
for. I don't think this should be fixed, not even in os.makedirs.
msg78810 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2009-01-02 15:00
Fixed this issue in r68161 by porting the solution for this in os.mkdirs 
to macostools.
Date User Action Args
2022-04-11 14:56:09adminsetgithub: 41619
2009-01-02 15:00:24ronaldoussorensetstatus: open -> closed
nosy: + ronaldoussoren
resolution: fixed
messages: + msg78810
2005-02-23 13:26:43jnebcreate