Problem with __del__ when Python is shutting down.
When using a Lock in a class, any program using this class will generate an error
#!/usr/bin/env python
# coding: utf8
from flufl.lock import Lock
class LockClass:
def __init__(self):
lock_file = '/tmp/lock.lock'
self.lock = Lock(lock_file)
def __del__(self):
del self.lock
myLockClass = LockClass()
Running this program generate the following error
Exception ignored in: <object repr() failed>
Traceback (most recent call last):
File "/.../python3.6/site-packages/flufl/lock/_lockfile.py", line 331, in __del__
File "/.../python3.6/site-packages/flufl/lock/_lockfile.py", line 326, in finalize
File "/.../python3.6/site-packages/flufl/lock/_lockfile.py", line 285, in unlock
File "/.../python3.6/site-packages/flufl/lock/_lockfile.py", line 312, in is_locked
File "/.../python3.6/site-packages/flufl/lock/_lockfile.py", line 459, in _touch
ImportError: sys.meta_path is None, Python is likely shutting down
A simple fix would be to change the __del__ method to something like this
def __del__(self):
try:
log.debug('__del__: {}'.format(self._lockfile))
if self._owned:
self.finalize()
except ImportError:
pass
Thanks for your work and this module !