Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a singleton in a module I am importing in my userSetup.py.
# Package/Module.py
class Singleton:
def get_instance(): ...
# userSetup.py:
from Package import Module
cls = Module.get_instance()
# In the script editor, I can use:
print(cls, Module)
# >>> (instance, module)
from Package import Module
cls2 = Module.get_instance()
cls == cls2
# >>> False
I suspect this is because the globals() from the userSetup.py gets passed into the script editor env and sys.modules stays empty.
While I dont plan to run this in the script editor, there will be other packages and modules or even shelves run from within Maya that will import the Module and all try to get the instance of the singelton
Any suggestions how to accomplish this without trusting my peeps that they dont `import Module`? Or without misusing pythons import system or having to pass globals() to any subsequent tool?
Solved! Go to Solution.