`Lease`: `__del__` after `logging` is gone
While working with Lease
s I have noticed that my Python script always crashes with:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/swatch/board.py", line 134, in __del__
File "/usr/local/lib/python3.11/site-packages/swatch/board.py", line 180, in retire
File "/usr/lib64/python3.11/logging/__init__.py", line 1488, in info
File "/usr/lib64/python3.11/logging/__init__.py", line 1744, in isEnabledFor
TypeError: 'NoneType' object is not callable
Exception ignored in: <function Lease.__del__ at 0x7f6f88372700>
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/swatch/board.py", line 134, in __del__
File "/usr/local/lib/python3.11/site-packages/swatch/board.py", line 180, in retire
File "/usr/lib64/python3.11/logging/__init__.py", line 1488, in info
File "/usr/lib64/python3.11/logging/__init__.py", line 1744, in isEnabledFor
TypeError: 'NoneType' object is not callable
Exception ignored in: <function Lease.__del__ at 0x7f6f88372700>
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/swatch/board.py", line 134, in __del__
File "/usr/local/lib/python3.11/site-packages/swatch/board.py", line 180, in retire
File "/usr/lib64/python3.11/logging/__init__.py", line 1488, in info
File "/usr/lib64/python3.11/logging/__init__.py", line 1744, in isEnabledFor
TypeError: 'NoneType' object is not callable
This happens after all my code runs, during the Python interpreter teardown and it seems that the logger is already gone by the time the system comes to call __del__
on the Lease
s that in turn hits retire
whose first line is a call to the logger.
What is odd is that in my code I use a context manager for the Lease
s, so it is unclear why they are being __del__
'ed when Python exits.
Perhaps a solution could be to factorise out retire
into a shim with the logging and a function without the logging that is called from both __del__
and retire
. If this makes sense, I can prepare a MR.