persist-queue
persist-queue copied to clipboard
Error logging can be improved when the DB write is not possible
The code block below creates a new dict but fails when the file system does not allow file locks (or something else related to permissions).
def _get_queue_mapper_db_sesh() -> persistqueue.PDict:
db_path = environ.get("GENERIC_EVENT_DB_PATH")
assert db_path is not None, f"Invalid queue mapping db path: {db_path}"
return persistqueue.PDict(
path=db_path,
name="generic_proxy_queues_mapppings",
multithreading=True,
)
But, the error points to a missing attribute at first instead of terminating the app at the DB lock error:
# Traceback (most recent call last):
# File "<string>", line 17, in <module>
# File "<string>", line 10, in _get_queue_mapper_db_sesh
# File "/opt/python/3.8.5/lib/python3.8/site-packages/persistqueue/pdict.py", line 22, in __init__
# super(PDict, self).__init__(path, name=name,
# File "/opt/python/3.8.5/lib/python3.8/site-packages/persistqueue/sqlbase.py", line 89, in __init__
# self._init()
# File "/opt/python/3.8.5/lib/python3.8/site-packages/persistqueue/sqlbase.py", line 101, in _init
# self._conn = self._new_db_connection(
# File "/opt/python/3.8.5/lib/python3.8/site-packages/persistqueue/sqlbase.py", line 129, in _new_db_connection
# conn.execute('PRAGMA journal_mode=WAL;')
# sqlite3.OperationalError: database is locked
# Exception ignored in: <function SQLiteBase.__del__ at 0x7fb9913efaf0>
# Traceback (most recent call last):
# File "/opt/python/3.8.5/lib/python3.8/site-packages/persistqueue/sqlbase.py", line 202, in __del__
# self._getter.close()
# AttributeError: 'PDict' object has no attribute '_getter'