From cbc970fc894db0f376f3fc581d9ad14248e137b0 Mon Sep 17 00:00:00 2001 From: Yang Zhang Date: Fri, 27 Sep 2019 14:49:55 +0800 Subject: [PATCH] Make weight download hack compatible with python 2 (#3432) --- ppdet/utils/checkpoint.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ppdet/utils/checkpoint.py b/ppdet/utils/checkpoint.py index f6be75ab8..a63dd1daf 100644 --- a/ppdet/utils/checkpoint.py +++ b/ppdet/utils/checkpoint.py @@ -17,6 +17,7 @@ from __future__ import division from __future__ import print_function from __future__ import unicode_literals +import errno import os import shutil import time @@ -57,9 +58,13 @@ def _get_weight_path(path): weight_path = map_path(path, WEIGHTS_HOME) lock_path = weight_path + '.lock' if not os.path.exists(weight_path): - os.makedirs(os.path.dirname(weight_path), exist_ok=True) + try: + os.makedirs(os.path.dirname(weight_path)) + except OSError as e: + if e.errno != errno.EEXIST: + raise with open(lock_path, 'w'): # touch - os.utime(lock_path) + os.utime(lock_path, None) if trainer_id == 0: get_weights_path(path) os.remove(lock_path) -- GitLab