Skip to content

Commit 133df4d

Browse files
Christopher Dunnjonmmease
Christopher Dunn
authored andcommitted
Fix race conditions in _permissions() (#1498)
1 parent b13b2ba commit 133df4d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Diff for: plotly/files.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,20 @@
2727
def _permissions():
2828
try:
2929
if not os.path.exists(PLOTLY_DIR):
30-
os.mkdir(PLOTLY_DIR)
30+
try:
31+
os.mkdir(PLOTLY_DIR)
32+
except Exception:
33+
# in case of race
34+
if not os.path.isdir(PLOTLY_DIR):
35+
raise
3136
with open(TEST_FILE, 'w') as f:
3237
f.write('testing\n')
33-
os.remove(TEST_FILE)
38+
try:
39+
os.remove(TEST_FILE)
40+
except Exception:
41+
pass
3442
return True
35-
except:
43+
except Exception: # Do not trap KeyboardInterrupt.
3644
return False
3745

3846

0 commit comments

Comments
 (0)