tendo icon indicating copy to clipboard operation
tendo copied to clipboard

'NoneType' has no attribute exit

Open InterStella0 opened this issue 3 years ago • 5 comments

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.

InterStella0 avatar Sep 10 '22 15:09 InterStella0

Hi, I couldn't replicate your use case. Can you help me with some more information? The code, perhaps?

liorp avatar Sep 29 '22 14:09 liorp

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.

liorp avatar Oct 01 '22 09:10 liorp

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.

InterStella0 avatar Oct 02 '22 02:10 InterStella0

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.

liorp avatar Oct 06 '22 19:10 liorp

Using context manager seems solid, better code flow for edge cases like this.

InterStella0 avatar Oct 07 '22 00:10 InterStella0