diff --git a/tools/cfg/copy_proto_python_file.py b/tools/cfg/copy_proto_python_file.py index 133b8cac87f1b764fa34842847e27159e6a61311..b81df4659f772239dffe9a0c414bcb6e15e69ab6 100644 --- a/tools/cfg/copy_proto_python_file.py +++ b/tools/cfg/copy_proto_python_file.py @@ -21,13 +21,14 @@ def copy_proto_files(src_proto_files, of_proto_python_dir, dst_proto_python_dir) if not os.path.exists(dst_file_dir): if dst_file_dir: - os.makedirs(dst_file_dir) + # use parameter exist_ok to avoid misjudgment under multithreading + os.makedirs(dst_file_dir, exist_ok=True) - if not os.path.exists(dst_file): + if ( + not os.path.exists(dst_file) + or os.stat(src_file).st_mtime - os.stat(dst_file).st_mtime > 0 + ): copyfile(src_file, dst_file) - else: - if os.stat(src_file).st_mtime - os.stat(dst_file).st_mtime > 0: - copyfile(src_file, dst_file) def main():