提交 925dd14b authored 作者: abergeron's avatar abergeron

Merge pull request #2394 from nouiz/lock

Do not make Theano cache code delete the lock directory. This fix proble...
...@@ -673,6 +673,10 @@ class ModuleCache(object): ...@@ -673,6 +673,10 @@ class ModuleCache(object):
continue continue
if not os.path.isdir(root): if not os.path.isdir(root):
continue continue
# Some sub directory we do not want the cache to mess
# with. This can cause problems with multiple process.
if os.path.split(root)[1] in ["lock_dir"]:
continue
files = os.listdir(root) files = os.listdir(root)
if not files or 'delete.me' in files: if not files or 'delete.me' in files:
rmtree(root, ignore_nocleanup=True, rmtree(root, ignore_nocleanup=True,
......
...@@ -24,6 +24,7 @@ AddConfigVar('compile.wait', ...@@ -24,6 +24,7 @@ AddConfigVar('compile.wait',
IntParam(5, lambda i: i > 0, allow_override=False), IntParam(5, lambda i: i > 0, allow_override=False),
in_c_key=False) in_c_key=False)
def _timeout_default(): def _timeout_default():
return config.compile.wait * 24 return config.compile.wait * 24
...@@ -37,6 +38,8 @@ period for running processes.""", ...@@ -37,6 +38,8 @@ period for running processes.""",
allow_override=False), allow_override=False),
in_c_key=False) in_c_key=False)
hostname = socket.gethostname()
def force_unlock(): def force_unlock():
""" """
...@@ -129,6 +132,7 @@ def set_lock_status(use_lock): ...@@ -129,6 +132,7 @@ def set_lock_status(use_lock):
# This is because None is a valid input for timeout # This is because None is a valid input for timeout
notset = object() notset = object()
def lock(tmp_dir, timeout=notset, min_wait=None, max_wait=None, verbosity=1): def lock(tmp_dir, timeout=notset, min_wait=None, max_wait=None, verbosity=1):
""" """
Obtain lock access by creating a given temporary directory (whose base will Obtain lock access by creating a given temporary directory (whose base will
...@@ -212,13 +216,14 @@ def lock(tmp_dir, timeout=notset, min_wait=None, max_wait=None, verbosity=1): ...@@ -212,13 +216,14 @@ def lock(tmp_dir, timeout=notset, min_wait=None, max_wait=None, verbosity=1):
other_host = read_owner.split('_')[2] other_host = read_owner.split('_')[2]
except IndexError: except IndexError:
other_host = () # make sure it isn't equal to any host other_host = () # make sure it isn't equal to any host
if other_host == socket.gethostname(): if other_host == hostname:
try: try:
# Just check if the other process still exist.
os.kill(int(read_owner.split('_')[0]), 0) os.kill(int(read_owner.split('_')[0]), 0)
except OSError: except OSError:
other_dead = True other_dead = True
except AttributeError: except AttributeError:
pass #os.kill does not exist on windows pass # os.kill does not exist on windows
except Exception: except Exception:
read_owner = 'failure' read_owner = 'failure'
if other_dead: if other_dead:
...@@ -305,7 +310,7 @@ def refresh_lock(lock_file): ...@@ -305,7 +310,7 @@ def refresh_lock(lock_file):
unique_id = '%s_%s_%s' % ( unique_id = '%s_%s_%s' % (
os.getpid(), os.getpid(),
''.join([str(random.randint(0, 9)) for i in range(10)]), ''.join([str(random.randint(0, 9)) for i in range(10)]),
socket.gethostname()) hostname)
lock_write = open(lock_file, 'w') lock_write = open(lock_file, 'w')
lock_write.write(unique_id + '\n') lock_write.write(unique_id + '\n')
lock_write.close() lock_write.close()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论