##// END OF EJS Templates
fix race condition in profiledir creation.
James Porter -
Show More
@@ -24,6 +24,7 b' Authors:'
24 import os
24 import os
25 import shutil
25 import shutil
26 import errno
26 import errno
27 import time
27
28
28 from IPython.config.configurable import LoggingConfigurable
29 from IPython.config.configurable import LoggingConfigurable
29 from IPython.utils.path import get_ipython_package_dir, expand_path
30 from IPython.utils.path import get_ipython_package_dir, expand_path
@@ -79,8 +80,16 b' class ProfileDir(LoggingConfigurable):'
79 if self._location_isset:
80 if self._location_isset:
80 raise RuntimeError("Cannot set profile location more than once.")
81 raise RuntimeError("Cannot set profile location more than once.")
81 self._location_isset = True
82 self._location_isset = True
82 if not os.path.isdir(new):
83 num_tries = 0
84 max_tries = 5
85 while not os.path.isdir(new):
86 try:
83 os.makedirs(new)
87 os.makedirs(new)
88 except OSError:
89 if num_tries > max_tries:
90 raise
91 num_tries += 1
92 time.sleep(0.5)
84
93
85 # ensure config files exist:
94 # ensure config files exist:
86 self.security_dir = os.path.join(new, self.security_dir_name)
95 self.security_dir = os.path.join(new, self.security_dir_name)
@@ -270,5 +279,3 b' class ProfileDir(LoggingConfigurable):'
270 if not os.path.isdir(profile_dir):
279 if not os.path.isdir(profile_dir):
271 raise ProfileDirError('Profile directory not found: %s' % profile_dir)
280 raise ProfileDirError('Profile directory not found: %s' % profile_dir)
272 return cls(location=profile_dir, config=config)
281 return cls(location=profile_dir, config=config)
273
274
General Comments 0
You need to be logged in to leave comments. Login now