提交 9ce3e397 authored 作者: Frederic's avatar Frederic

Take the compiledir lock only if the op generate c code.

上级 c4e6bded
...@@ -891,10 +891,11 @@ class ModuleCache(object): ...@@ -891,10 +891,11 @@ class ModuleCache(object):
hash_key = hash(key) hash_key = hash(key)
key_data = None key_data = None
# We have never seen this key before. # We have never seen this key before.
# Acquire lock before creating things in the compile cache,
# to avoid that other processes remove the compile dir while it # We acquire the lock later only if we where able to
# is still empty. # generate c code Otherwise, we would take the lock for op
compilelock.get_lock() # that have only a perform().
lock_taken = False
# This try/finally block ensures that the lock is released once we # This try/finally block ensures that the lock is released once we
# are done writing in the cache file or after raising an exception. # are done writing in the cache file or after raising an exception.
try: try:
...@@ -918,6 +919,10 @@ class ModuleCache(object): ...@@ -918,6 +919,10 @@ class ModuleCache(object):
# The first compilation step is to yield the source code. # The first compilation step is to yield the source code.
src_code = compile_steps.next() src_code = compile_steps.next()
module_hash = get_module_hash(src_code, key) module_hash = get_module_hash(src_code, key)
# The op have c_code, so take the lock.
compilelock.get_lock()
lock_taken = True
if module_hash in self.module_hash_to_key_data: if module_hash in self.module_hash_to_key_data:
_logger.debug("Duplicated module! Will re-use the " _logger.debug("Duplicated module! Will re-use the "
"previous one") "previous one")
...@@ -1039,7 +1044,7 @@ class ModuleCache(object): ...@@ -1039,7 +1044,7 @@ class ModuleCache(object):
finally: finally:
# Release lock if needed. # Release lock if needed.
if not keep_lock: if not keep_lock and lock_taken:
compilelock.release_lock() compilelock.release_lock()
# Update map from key to module name for all keys associated to # Update map from key to module name for all keys associated to
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论