Skip to content

Instantly share code, notes, and snippets.

View kaulketh's full-sized avatar
💭
#iwantplutobackasplanet

Thomas kaulketh

💭
#iwantplutobackasplanet
  • Germany
  • 09:22 (UTC +02:00)
View GitHub Profile
@kaulketh
kaulketh / singleton.py
Created April 15, 2020 19:03
python singleton with metaclass
class _Singleton(type):
""" A metaclass that creates a Singleton base class when called.
Works in Python 2 & 3
https://www.it-swarm.dev/de/python/ein-singleton-python-erstellen/972393601
"""
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(_Singleton, cls).__call__(*args,