首页 > 解决方案 > 完成蝗虫实例后是否可以运行代码?

问题描述

假设这是我将在终端中运行的主要文件,即locusts -f main.py. 在 locust 实例终止或达到时间限制后,是否可以让它也运行代码?可能是清理脚本或发送在某处生成的 csv 报告。

class setup(HttpUser):
     wait_time = between(3, 5)
     host = 'www.example.com'
     tasks = [a, b, c...]

#do something after time limit reached

标签: pythonlocust

解决方案


有一个test_stop事件(https://docs.locust.io/en/stable/extending-locust.html)以及一个quitting事件(https://docs.locust.io/en/stable/api.html#locust .event.Events.quitting)您可以用于此目的。


推荐阅读