提交 2315bc94 authored 作者: nouiz's avatar nouiz

Merge pull request #270 from delallea/cache_unlock

Added new command 'theano-cache unlock'
......@@ -28,10 +28,14 @@ elif sys.argv[1] in ('clear'):
(len(items), ', '.join(items)))
elif sys.argv[1] in ('list'):
theano.gof.compiledir.print_compiledir_content()
elif sys.argv[1] == 'unlock':
theano.gof.compilelock.force_unlock()
print 'Lock successfully removed!'
else:
print 'command "%s" not recognized' % sys.argv[1]
print 'Type "theano-cache" to print the cache location'
print 'Type "theano-cache clear" to erase the cache'
print 'Type "theano-cache list" to print the cache content'
print 'Type "theano-cache unlock" to unlock the cache directory'
sys.exit(1)
......@@ -21,9 +21,27 @@ timeout_before_override = 120
# 'refresh_every' seconds.
refresh_every = 60
def get_lock():
def force_unlock():
"""
Delete the compilation lock if someone else has it.
"""
global timeout_before_override
timeout_backup = timeout_before_override
timeout_before_override = 0
try:
get_lock(min_wait=0, max_wait=0.001)
release_lock()
finally:
timeout_before_override = timeout_backup
def get_lock(**kw):
"""
Obtain lock on compilation directory.
:param kw: Additional arguments to be forwarded to the `lock` function when
acquiring the lock.
"""
if not hasattr(get_lock, 'n_lock'):
# Initialization.
......@@ -47,7 +65,7 @@ def get_lock():
if get_lock.lock_is_enabled:
# Only really try to acquire the lock if we do not have it already.
if get_lock.n_lock == 0:
lock(get_lock.lock_dir, timeout = timeout_before_override)
lock(get_lock.lock_dir, timeout=timeout_before_override, **kw)
atexit.register(Unlocker.unlock, get_lock.unlocker)
# Store time at which the lock was set.
get_lock.start_time = time.time()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论