Custom UI never closes when opened from a shortcut

I have been working on a custom ui which works fine when it is opened from the addon section in Kodi, but if it is opened from favorites or set as a favorite , submenu and or shortcut. It will never close when the user exists. Instead it will constantly reopen.
Below is the code I am using and it looks like other custom ui addons. This only happens when using windowxml. When using a windowxmldialog it closes as expected.

Any thoughts?

PHP Code:
if (__name__ == '__main__'):
    
from resources.lib.gui.maingui import main;
    
    
main();

exit();