From 7c2b283b6fb8158f1c87cf3fa39ee9e5fb1a6809 Mon Sep 17 00:00:00 2001 From: MIC3LHN Date: Tue, 4 May 2021 16:10:05 +0000 Subject: [PATCH] Call the `User` instance method `stop()` This allows to use an overridden `stop()` method when the Locust runner stops the user, which allows for more flexibility without introducing additional complexity. One of the use cases is being able to close a gRPC channel before killing the user greenlet. --- locust/runners.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/locust/runners.py b/locust/runners.py index f3f4684c37..0c38fc3825 100644 --- a/locust/runners.py +++ b/locust/runners.py @@ -250,10 +250,10 @@ def stop_users(self, user_count, stop_rate=None): # User called runner.quit(), so dont block waiting for killing to finish" user_to_stop._group.killone(user_to_stop._greenlet, block=False) elif self.environment.stop_timeout: - async_calls_to_stop.add(gevent.spawn_later(0, User.stop, user_to_stop, force=False)) + async_calls_to_stop.add(gevent.spawn_later(0, user_to_stop.stop, force=False)) stop_group.add(user_to_stop._greenlet) else: - async_calls_to_stop.add(gevent.spawn_later(0, User.stop, user_to_stop, force=True)) + async_calls_to_stop.add(gevent.spawn_later(0, user_to_stop.stop, force=True)) if to_stop: gevent.sleep(sleep_time) else: