python装饰器一般用来做预处理,或者数据收集,那么它具体是怎么工作的呢?
分析线面的代码可以得出结论,可以复制代码后自行打断点进行调试
def task(weight=1): # 代码被执行的时候首先会到这里,执行装饰器
def decorator_func(func):
func.locust_task_weight = weight
return func
return decorator_func # 代码执行的这里的时候会返回来源函数,获取到来源函数的对象共装饰器使用
@task(1)
def test():
print(test)
if __name__ == '__main__':
test()