ATLAS Offline Software
Loading...
Searching...
No Matches
singleton.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
4 """! Metaclass for implementing the Singleton pattern.
5
6 @author James Robinson <james.robinson@cern.ch>
7 """
8
9 _instances = {}
10
11 def __call__(cls, *args, **kwargs):
12 """! Retrieve the singleton instance, creating if necessary."""
13 if cls not in cls._instances:
14 cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
15 return cls._instances[cls]
Metaclass for implementing the Singleton pattern.
Definition singleton.py:3
__call__(cls, *args, **kwargs)
Retrieve the singleton instance, creating if necessary.
Definition singleton.py:11