前言
翻出之前做个压测项,看到locust中对等待时间的实现方式感到好奇,于是总结下来。
源代码实现
def between(min_wait, max_wait):
"""
Returns a function that will return a random number between min_wait and max_wait.
Example::
class MyUser(User):
# wait between 3.0 and 10.5 seconds after each task
wait_time = between(3.0, 10.5)
"""
return lambda instance: min_wait + random.random() * (max_wait - min_wait)
def constant(wait_time):
"""
Returns a function that just returns the number specified by t

最低0.47元/天 解锁文章
812





