Python简单单例模式-线程不安全
# -*- coding: utf-8 -*-
# @Time :2020/6/24 10:17
# @Author :12257
# @SoftWare :PyCharm
class Singleton:
__instance = None
def __new__(cls, *args, **kwargs):
if cls.__instance is None:
cls.__instance = super(Singleton, cls).__new__(cls, *args, **kwargs)
return cls.__instance
if __name__ == '__main__':
s1 = Singleton
s2 = Singleton
print(id(s1),id(s2))
print(s1 is s2)