Skip to content

Commit

Permalink
Fix FilexExistsError due to race condition (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrebscher committed Jul 14, 2020
1 parent 5eb9017 commit 1c4d4b9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions surprise/builtin_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from six.moves.urllib.request import urlretrieve
import zipfile
from collections import namedtuple
import os
import errno

from os.path import join
from collections import namedtuple
from six.moves.urllib.request import urlretrieve


def get_dataset_dir():
Expand All @@ -19,8 +21,12 @@ def get_dataset_dir():

folder = os.environ.get('SURPRISE_DATA_FOLDER', os.path.expanduser('~') +
'/.surprise_data/')
if not os.path.exists(folder):
try:
os.makedirs(folder)
except OSError as e:
if e.errno != errno.EEXIST:
# reraise exception if folder does not exist and creation failed.
raise

return folder

Expand Down

0 comments on commit 1c4d4b9

Please sign in to comment.