Skip to content

Commit

Permalink
Merge pull request #1728 from locustio/ensure-runner.quit-finishes-ev…
Browse files Browse the repository at this point in the history
…en-when-users-are-broken

Ensure runner.quit finishes even when users are broken
  • Loading branch information
cyberw committed Mar 11, 2021
2 parents fddfefe + 0d58646 commit f61ae7d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions locust/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import socket
import sys
import traceback
from typing import Type, List
import warnings
from uuid import uuid4
from time import time
Expand Down Expand Up @@ -132,7 +133,7 @@ def cpu_log_warning(self):
return True
return False

def weight_users(self, amount):
def weight_users(self, amount) -> List[Type[User]]:
"""
Distributes the amount of users for each WebLocust-class according to it's weight
returns a list "bucket" with the weighted users
Expand Down Expand Up @@ -218,12 +219,18 @@ def stop_users(self, user_count, stop_rate=None):
bucket = self.weight_users(user_count)
user_count = len(bucket)
to_stop = []
for g in self.user_greenlets:
for l in bucket:
user = g.args[0]
if isinstance(user, l):
for user_greenlet in self.user_greenlets:
try:
user = user_greenlet.args[0]
except IndexError:
logger.error(
"While stopping users, we encountered a user that didnt have proper args %s", user_greenlet
)
continue
for user_class in bucket:
if isinstance(user, user_class):
to_stop.append(user)
bucket.remove(l)
bucket.remove(user_class)
break

if not to_stop:
Expand Down

0 comments on commit f61ae7d

Please sign in to comment.