"""
Utility functions used in pyiron.
In order to be accessible from anywhere in pyiron, they *must* remain free of any imports from pyiron!
"""
from abc import ABCMeta
[docs]
class Singleton(ABCMeta):
"""
Implemented with suggestions from
http://stackoverflow.com/questions/6760685/creating-a-singleton-in-python
"""
_instances: dict[type, object] = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super().__call__(*args, **kwargs)
return cls._instances[cls]