码迷,mamicode.com
首页 > 其他好文 > 详细

一段神奇的代码

时间:2019-05-06 23:37:19      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:turn   port   return   class   fun   div   art   star   utf-8   

# -*- coding: utf-8 -*-
# @Time    : 2019/4/21 17:13
# @Author  : Just
# @Email   : 1785780475@qq.com
# @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

 

一段神奇的代码

标签:turn   port   return   class   fun   div   art   star   utf-8   

原文地址:https://www.cnblogs.com/just-do/p/10822749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!