try:
    os.makedirs(dest_dir)
except OSError as exc:
    if exc.errno != errno.EEXIST:
        raise
shutil.copyfile(source_name, dest_name)
Debugging strategy for a bug (apparently) affected by timing