Issue 1149804: macostools.mkdirs: not thread-safe (original) (raw)

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): return head, tail = os.path.split(dst) if os.sep == ':' and not ':' in head: head = head + ':' mkdirs(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! pass else: raise - Jurjen
msg60678 - (view) Author: Just van Rossum (jvr) * (Python triager) Date: 2005-03-01 08:40
Logged In: YES user_id=92689 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 user_id=92689 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 user_id=139309 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.
History
Date User Action Args
2022-04-11 14:56:09 admin set github: 41619
2009-01-02 15:00:24 ronaldoussoren set status: open -> closednosy: + ronaldoussorenresolution: fixedmessages: +
2005-02-23 13:26:43 jneb create