一段神奇的代码
Posted just-do
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一段神奇的代码相关的知识,希望对你有一定的参考价值。
# -*- coding: utf-8 -*- # @Time : 2019/4/21 17:13 # @Author : Just # @Email : [email protected] # @File : testCSS.py import threading import time class test(object): _instance_lock = threading.Lock() def __init__(self,name): self.name = name def __eq__(self, other): return self.name == other.name def __hash__(self): return hash(self.name) def __new__(cls, *args, **kwargs): with cls._instance_lock: if not hasattr(cls,‘_instance‘): cls._instance = object.__new__(cls, *args, **kwargs) return cls._instance def __call__(self,func, *args, **kwargs): def inner(*args, **kwargs): start_time = time.time() result = func(*args, **kwargs) end_time = time.time() print(‘speend time:‘,end_time-start_time) return result return inner
以上是关于一段神奇的代码的主要内容,如果未能解决你的问题,请参考以下文章