'NoneType' has no attribute exit
try:
me = singleton.SingleInstance()
except tendo.singleton.SingleInstanceException:
sys.exit(0)
For some reason, this code produces an error when exiting the program.
Exception ignored in: <function SingleInstance.__del__ at 0x00000224E7351510>
Traceback (most recent call last):
File "C:\Users\sarah\PycharmProjects\stella_manager_gui\venv\lib\site-packages\tendo\singleton.py", line 91, in __del__
AttributeError: 'NoneType' object has no attribute 'exit'
Unloggable error: 'NoneType' object has no attribute 'platform'
I'm not sure how this happens, looking at the source it seems like sys is somehow a NoneType. If it helps, I'm using pyqt5 with qasync together with tendo on Windows 11. This error produces when I close it with the X button on pyqt instead of keyboard interrupt.
Hi, I couldn't replicate your use case. Can you help me with some more information? The code, perhaps?
Hi, in order to understand this issue I'd be happy to receive a code example which fails - I tried running yours but it ran successfully.
Therefore, I suspect it has something to do with your dependencies.
Hi, It seems like this only happens with a library I was using which was qasync, it's a PyQt async wrapper.
import sys
import qasync
import tendo
from tendo import singleton
try:
me = singleton.SingleInstance()
except tendo.singleton.SingleInstanceException:
sys.exit(0)
def cleanup():
...
sys.exit(0)
async def window():
cleanup()
qasync.run(window())
Which produces
Exception ignored in: <function SingleInstance.__del__ at 0x0000023F40D696C0>
Traceback (most recent call last):
File "C:\Users\sarah\PycharmProjects\stella_manager_gui\venv\lib\site-packages\tendo\singleton.py", line 91, in __del__
AttributeError: 'NoneType' object has no attribute 'exit'
Unloggable error: 'NoneType' object has no attribute 'platform'
So technically it's a dependency issue.
This occurs because of the way singleton is cleared using del. We should implement something such as context manager with enter and exit, since using del exposes us to bugs like this.
Using context manager seems solid, better code flow for edge cases like this.