From 1c537b0b79cd595dd4e667b48934ece7b4c5dae7 Mon Sep 17 00:00:00 2001 From: Gregory Ashton <gregory.ashton@ligo.org> Date: Tue, 11 Jun 2019 21:46:01 -0500 Subject: [PATCH] Add a catch for broken resume files If the dynesty pickle file is broken, it will print a warning that the reading of the resume file and otherwise continue as if the resume file didn't exist --- bilby/core/sampler/dynesty.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bilby/core/sampler/dynesty.py b/bilby/core/sampler/dynesty.py index f6c40ebf1..b26a7988d 100644 --- a/bilby/core/sampler/dynesty.py +++ b/bilby/core/sampler/dynesty.py @@ -307,10 +307,14 @@ class Dynesty(NestedSampler): if os.path.isfile(self.resume_file): logger.info("Reading resume file {}".format(self.resume_file)) - with open(self.resume_file, 'rb') as file: - saved = pickle.load(file) - logger.info( - "Succesfuly read resume file {}".format(self.resume_file)) + try: + with open(self.resume_file, 'rb') as file: + saved = pickle.load(file) + logger.info( + "Succesfuly read resume file {}".format(self.resume_file)) + except EOFError as e: + logger.warning("Resume file reading failed with error {}".format(e)) + return False self.sampler.saved_u = list(saved['unit_cube_samples']) self.sampler.saved_v = list(saved['physical_samples']) -- GitLab