From 539d7bcb4476883771f0492b3a3774048de5163d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tanel=20Alum=C3=A4e?= Date: Thu, 21 Nov 2019 20:27:39 +0200 Subject: [PATCH] Avoid race condition in creating checkpoint directories (#530) * Avoid race condition in creating checkpoint directories In multi-GPU training, several processes run the code that creates checkpoint dirs. This fix avoids a probably rare situation (but it happened to me) where another process created a dir between the `exists` check and the `makedirs` call. * Remove the now unneeded check for dir existence --- pytorch_lightning/callbacks/pt_callbacks.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pytorch_lightning/callbacks/pt_callbacks.py b/pytorch_lightning/callbacks/pt_callbacks.py index a08f359aed111..71d1bd8fad8e4 100644 --- a/pytorch_lightning/callbacks/pt_callbacks.py +++ b/pytorch_lightning/callbacks/pt_callbacks.py @@ -198,8 +198,7 @@ def __init__(self, filepath, monitor='val_loss', verbose=0, self.monitor = monitor self.verbose = verbose self.filepath = filepath - if not os.path.exists(filepath): - os.makedirs(filepath) + os.makedirs(filepath, exist_ok=True) self.save_top_k = save_top_k self.save_weights_only = save_weights_only self.period = period