提交 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): ...@@ -57,7 +57,10 @@ def lock_ctx(lock_dir=None, keep_lock=False, **kw):
release_lock() 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. Obtain lock on compilation directory.
...@@ -113,6 +116,9 @@ def get_lock(lock_dir=None, **kw): ...@@ -113,6 +116,9 @@ def get_lock(lock_dir=None, **kw):
get_lock.n_lock += 1 get_lock.n_lock += 1
get_lock = _get_lock
def release_lock(): def release_lock():
""" """
Release lock on compilation directory. Release lock on compilation directory.
...@@ -344,10 +350,6 @@ class Unlocker(object): ...@@ -344,10 +350,6 @@ class Unlocker(object):
def __init__(self, tmp_dir): def __init__(self, tmp_dir):
self.tmp_dir = 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): def __del__(self):
self.unlock() self.unlock()
...@@ -360,7 +362,6 @@ class Unlocker(object): ...@@ -360,7 +362,6 @@ class Unlocker(object):
should be allowed for multiple jobs running in parallel to should be allowed for multiple jobs running in parallel to
unlock the same directory at the same time (e.g. when reaching unlock the same directory at the same time (e.g. when reaching
their timeout limit). their timeout limit).
""" """
# If any error occurs, we assume this is because someone else tried to # If any error occurs, we assume this is because someone else tried to
# unlock this directory at the same time. # unlock this directory at the same time.
...@@ -369,10 +370,10 @@ class Unlocker(object): ...@@ -369,10 +370,10 @@ class Unlocker(object):
# remove the file may fail (e.g. because for some reason this file does # 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. # not exist), we still want to try and remove the directory.
try: try:
self.os.remove(self.path.join(self.tmp_dir, 'lock')) os.remove(os.path.join(self.tmp_dir, 'lock'))
except Exception: except Exception:
pass pass
try: try:
self.os.rmdir(self.tmp_dir) os.rmdir(self.tmp_dir)
except Exception: except Exception:
pass pass
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论