From 6230371ccebb2a8170621d00e1d97beb6aaf8381 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Tue, 2 Nov 2021 10:18:38 -0400 Subject: [PATCH] FIX: Retry renaming pkl(z) files on fail --- nipype/utils/filemanip.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nipype/utils/filemanip.py b/nipype/utils/filemanip.py index 03786ec935..a8947a3d0d 100644 --- a/nipype/utils/filemanip.py +++ b/nipype/utils/filemanip.py @@ -718,7 +718,15 @@ def savepkl(filename, record, versioning=False): tmpfile = filename + ".tmp" with pkl_open(tmpfile, "wb") as pkl_file: pkl_file.write(content) - os.rename(tmpfile, filename) + for _ in range(5): + try: + os.rename(tmpfile, filename) + break + except FileNotFoundError as e: + fmlogger.debug(str(e)) + sleep(2) + else: + raise e rst_levels = ["=", "-", "~", "+"]