This checks if a directory exists and then calls mkdir to create it. During automation or scripting where parallelism can come into play this can cause a race condition easily:
knack.util.ensure_dir
def ensure_dir(d):
""" Create a directory if it doesn't exist """
if not os.path.isdir(d):
os.makedirs(d)
To prevent this race condition, use try/expect: to create the directory, then ignore "File exists" errors, which mean the directory was there.
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST:
raise
This checks if a directory exists and then calls mkdir to create it. During automation or scripting where parallelism can come into play this can cause a race condition easily:
knack.util.ensure_dir
To prevent this race condition, use try/expect: to create the directory, then ignore "File exists" errors, which mean the directory was there.
Or for 3.2+