From 391530fde4bfa34878b5fdea4f8985c1b4d41519 Mon Sep 17 00:00:00 2001 From: Christopher Dunn Date: Sat, 6 Apr 2019 06:43:02 -0700 Subject: [PATCH] Fix race conditions --- plotly/files.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/plotly/files.py b/plotly/files.py index 0973a01450c..661382bc576 100644 --- a/plotly/files.py +++ b/plotly/files.py @@ -27,12 +27,20 @@ def _permissions(): try: if not os.path.exists(PLOTLY_DIR): - os.mkdir(PLOTLY_DIR) + try: + os.mkdir(PLOTLY_DIR) + except Exception: + # in case of race + if not os.path.isdir(PLOTLY_DIR): + raise with open(TEST_FILE, 'w') as f: f.write('testing\n') - os.remove(TEST_FILE) + try: + os.remove(TEST_FILE) + except Exception: + pass return True - except: + except Exception: # Do not trap KeyboardInterrupt. return False