From fd8452b5c6e27ce2c8a6a5bb5378be2abf34392b Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Sat, 16 Feb 2019 10:17:01 -0500 Subject: [PATCH] Add exception handling for failure to return to original directory Fixes #1552 --- cleanup.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cleanup.py b/cleanup.py index b78df372..dcef7789 100644 --- a/cleanup.py +++ b/cleanup.py @@ -33,7 +33,17 @@ class WorkingDirectory(object): return self def __exit__(self, exc_type, exc_val, exc_tb): - os.chdir(self.original_directory) + try: + os.chdir(self.original_directory) + except OSError as error: + print( + 'Unable to return to {original_directory}: {error}\n' + 'Continuing in {working_directory}'.format( + original_directory=self.original_directory, + error=error, + working_directory=self.working_directory, + ) + ) def module_path(module=__file__, parent=False):