I was wondering if this approach for creating a singleton was correct.
my_class.py
class MyClass(object):
def a_method(self):
print("Hello World")
...
MY_CLASS_SINGLETON = MyClass()
another module:
from my_class import MY_CLASS_SINGLETON
if __name__ == "__main__":
MY_CLASS_SINGLETON.a_method()
So this code is working for me, but my wonder is if the garbage collector could destroy the MY_CLASS_SINGLETON
instance before it is used by any other module, as at the end it is just a temporary variable inside the my_class.py
module.