提交 37676843 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Another attempt at fixing the errors on shutdown with Unlocker.

上级 66b329e7
......@@ -57,7 +57,10 @@ def lock_ctx(lock_dir=None, keep_lock=False, **kw):
release_lock()
def get_lock(lock_dir=None, **kw):
# We define this name with an underscore so that python shutdown
# deletes this before non-underscore names (like os). We need to do
# it this way to avoid errors on shutdown.
def _get_lock(lock_dir=None, **kw):
"""
Obtain lock on compilation directory.
......@@ -113,6 +116,9 @@ def get_lock(lock_dir=None, **kw):
get_lock.n_lock += 1
get_lock = _get_lock
def release_lock():
"""
Release lock on compilation directory.
......@@ -344,10 +350,6 @@ class Unlocker(object):
def __init__(self, tmp_dir):
self.tmp_dir = tmp_dir
# Keep a pointer to the 'os' module, otherwise it may not be accessible
# anymore in the __del__ method.
self.os = os
self.path = os.path
def __del__(self):
self.unlock()
......@@ -360,7 +362,6 @@ class Unlocker(object):
should be allowed for multiple jobs running in parallel to
unlock the same directory at the same time (e.g. when reaching
their timeout limit).
"""
# If any error occurs, we assume this is because someone else tried to
# unlock this directory at the same time.
......@@ -369,10 +370,10 @@ class Unlocker(object):
# remove the file may fail (e.g. because for some reason this file does
# not exist), we still want to try and remove the directory.
try:
self.os.remove(self.path.join(self.tmp_dir, 'lock'))
os.remove(os.path.join(self.tmp_dir, 'lock'))
except Exception:
pass
try:
self.os.rmdir(self.tmp_dir)
os.rmdir(self.tmp_dir)
except Exception:
pass
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论