zoukankan      html  css  js  c++  java
  • python 装饰方法

        def _concurrent(func):
            @wraps(func) # 加入这个的目的是保持原来方法的属性
            def arg_wrapper(self, *args, **kwargs):
                try:
                    jc = self.available_jc.pop()
                    # return f is function
                    f = getattr(jc, func.__name__)
                    r = f(*args, **kwargs)
                    self.available_jc.append(jc)
                    return r
                except IndexError:
                    raise RuntimeError('Too many concurrent connections!'
                                       'Try to increase the value of "max_concurrency", '
                                       'currently =%d' % self.max_concurrency)
    
            return arg_wrapper
        @_concurrent
        def subjective_judge(self, **kwargs):
            pass
        @property
        @_concurrent
        def server_status(self):
            pass
  • 相关阅读:
    表的相关内容
    数据类型
    mysql入门练习
    mysql入门
    协程
    多进程
    装饰器
    网络编程
    心路历程
    gensim的使用
  • 原文地址:https://www.cnblogs.com/callyblog/p/10396022.html
Copyright © 2011-2022 走看看