#!/usr/bin/python
# -*- coding: UTF-8 -*-
import time
import threading
class CHGlobal(object):
hello = 'HAHA'
_instance_lock = threading.Lock()
def __init__(self):
time.sleep(1)
@classmethod
def instance(cls, *args, **kwargs):
with CHGlobal._instance_lock:
if not hasattr(CHGlobal, "_instance"):
CHGlobal._instance = CHGlobal(*args, **kwargs)
return CHGlobal._instance
def test(self):
print("CHGlobal单例测试")
12-08
2784