提交 9f0f4fd8 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Added new command 'theano-cache unlock'

This can be used to unlock the compilation directory without having to wait two minutes, or having to manually delete a file.
上级 2d774b33
...@@ -28,10 +28,14 @@ elif sys.argv[1] in ('clear'): ...@@ -28,10 +28,14 @@ elif sys.argv[1] in ('clear'):
(len(items), ', '.join(items))) (len(items), ', '.join(items)))
elif sys.argv[1] in ('list'): elif sys.argv[1] in ('list'):
theano.gof.compiledir.print_compiledir_content() theano.gof.compiledir.print_compiledir_content()
elif sys.argv[1] == 'unlock':
theano.gof.compilelock.force_unlock()
print 'Lock successfully removed!'
else: else:
print 'command "%s" not recognized' % sys.argv[1] print 'command "%s" not recognized' % sys.argv[1]
print 'Type "theano-cache" to print the cache location' print 'Type "theano-cache" to print the cache location'
print 'Type "theano-cache clear" to erase the cache' print 'Type "theano-cache clear" to erase the cache'
print 'Type "theano-cache list" to print the cache content' print 'Type "theano-cache list" to print the cache content'
print 'Type "theano-cache unlock" to unlock the cache directory'
sys.exit(1) sys.exit(1)
...@@ -21,9 +21,27 @@ timeout_before_override = 120 ...@@ -21,9 +21,27 @@ timeout_before_override = 120
# 'refresh_every' seconds. # 'refresh_every' seconds.
refresh_every = 60 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. 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'): if not hasattr(get_lock, 'n_lock'):
# Initialization. # Initialization.
...@@ -47,7 +65,7 @@ def get_lock(): ...@@ -47,7 +65,7 @@ def get_lock():
if get_lock.lock_is_enabled: if get_lock.lock_is_enabled:
# Only really try to acquire the lock if we do not have it already. # Only really try to acquire the lock if we do not have it already.
if get_lock.n_lock == 0: 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) atexit.register(Unlocker.unlock, get_lock.unlocker)
# Store time at which the lock was set. # Store time at which the lock was set.
get_lock.start_time = time.time() get_lock.start_time = time.time()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论