提交 e692e389 authored 作者: Michael Osthege's avatar Michael Osthege 提交者: Brandon T. Willard

Remove theano.compile.compilelock.set_lock_status

上级 ffbe1f76
...@@ -111,12 +111,9 @@ case if ``borrow`` was True, the thunk would be allowed to reuse (or ...@@ -111,12 +111,9 @@ case if ``borrow`` was True, the thunk would be allowed to reuse (or
:attr:`config.blas__ldflags`, you will need to manually remove your compile cache, :attr:`config.blas__ldflags`, you will need to manually remove your compile cache,
using ``Theano/bin/theano-cache clear`` using ``Theano/bin/theano-cache clear``
Theano also implements a lock mechanism that prevents Theano also implements a lock mechanism that prevents multiple compilations
multiple compilations within the same compilation directory (to avoid within the same compilation directory (to avoid crashes with parallel
crashes with paralell execution of some scripts). This mechanism is execution of some scripts).
currently enabled by default, but if it causes any problem it may be
disabled using the function
``theano.compile.compilelock.set_lock_status(..)``.
Step 4 - Wrap the thunk in a pretty package Step 4 - Wrap the thunk in a pretty package
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...@@ -125,4 +122,3 @@ The thunk returned by the linker along with input and output ...@@ -125,4 +122,3 @@ The thunk returned by the linker along with input and output
containers is unwieldy. ``function`` hides that complexity away so containers is unwieldy. ``function`` hides that complexity away so
that it can be used like a normal function with arguments and return that it can be used like a normal function with arguments and return
values. values.
...@@ -20,7 +20,6 @@ __all__ = [ ...@@ -20,7 +20,6 @@ __all__ = [
"lock", "lock",
"lock_ctx", "lock_ctx",
"release_lock", "release_lock",
"set_lock_status",
] ]
...@@ -72,9 +71,6 @@ def _get_lock(lock_dir=None, **kw): ...@@ -72,9 +71,6 @@ def _get_lock(lock_dir=None, **kw):
if not hasattr(get_lock, "n_lock"): if not hasattr(get_lock, "n_lock"):
# Initialization. # Initialization.
get_lock.n_lock = 0 get_lock.n_lock = 0
if not hasattr(get_lock, "lock_is_enabled"):
# Enable lock by default.
get_lock.lock_is_enabled = True
get_lock.lock_dir = lock_dir get_lock.lock_dir = lock_dir
get_lock.unlocker = Unlocker(get_lock.lock_dir) get_lock.unlocker = Unlocker(get_lock.lock_dir)
else: else:
...@@ -86,33 +82,32 @@ def _get_lock(lock_dir=None, **kw): ...@@ -86,33 +82,32 @@ def _get_lock(lock_dir=None, **kw):
get_lock.lock_dir = lock_dir get_lock.lock_dir = lock_dir
get_lock.unlocker = Unlocker(get_lock.lock_dir) get_lock.unlocker = Unlocker(get_lock.lock_dir)
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, **kw)
lock(get_lock.lock_dir, **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() else:
else: # Check whether we need to 'refresh' the lock. We do this
# Check whether we need to 'refresh' the lock. We do this # every 'config.compile__timeout / 2' seconds to ensure
# every 'config.compile__timeout / 2' seconds to ensure # no one else tries to override our lock after their
# no one else tries to override our lock after their # 'config.compile__timeout' timeout period.
# 'config.compile__timeout' timeout period. if get_lock.start_time is None:
if get_lock.start_time is None: # This should not happen. So if this happen, clean up
# This should not happen. So if this happen, clean up # the lock state and raise an error.
# the lock state and raise an error. while get_lock.n_lock > 0:
while get_lock.n_lock > 0: release_lock()
release_lock() raise Exception(
raise Exception( "For some unknow reason, the lock was already "
"For some unknow reason, the lock was already " "taken, but no start time was registered."
"taken, but no start time was registered." )
) now = time.time()
now = time.time() if now - get_lock.start_time > config.compile__timeout / 2:
if now - get_lock.start_time > config.compile__timeout / 2: lockpath = os.path.join(get_lock.lock_dir, "lock")
lockpath = os.path.join(get_lock.lock_dir, "lock") _logger.info(f"Refreshing lock {lockpath}")
_logger.info(f"Refreshing lock {lockpath}") refresh_lock(lockpath)
refresh_lock(lockpath) get_lock.start_time = now
get_lock.start_time = now
get_lock.n_lock += 1 get_lock.n_lock += 1
...@@ -127,26 +122,11 @@ def release_lock(): ...@@ -127,26 +122,11 @@ def release_lock():
get_lock.n_lock -= 1 get_lock.n_lock -= 1
assert get_lock.n_lock >= 0 assert get_lock.n_lock >= 0
# Only really release lock once all lock requests have ended. # Only really release lock once all lock requests have ended.
if get_lock.lock_is_enabled and get_lock.n_lock == 0: if get_lock.n_lock == 0:
get_lock.start_time = None get_lock.start_time = None
get_lock.unlocker.unlock(force=False) get_lock.unlocker.unlock(force=False)
def set_lock_status(use_lock):
"""
Enable or disable the lock on the compilation directory (which is enabled
by default). Disabling may make compilation slightly faster (but is not
recommended for parallel execution).
Parameters
----------
use_lock : bool
Whether to use the compilation lock or not.
"""
get_lock.lock_is_enabled = 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()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论