MCPcopy
hub / github.com/locustio/locust / _user_gen

Method _user_gen

locust/dispatch.py:370–388  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

368 return users_on_workers, user_gen, worker_gen, active_users
369
370 def _user_gen(self) -> Iterator[str | None]:
371 weighted_users_gen = _kl_generator((u.__name__, u.weight) for u in self._user_classes if not u.fixed_count)
372
373 while True:
374 if self._try_dispatch_fixed: # Fixed_count users are spawned before weight users.
375 # Some peoples treat this implementation detail as a feature.
376 self._try_dispatch_fixed = False
377 fixed_users_missing = [
378 (u.__name__, miss)
379 for u in self._user_classes
380 if u.fixed_count and (miss := u.fixed_count - self._get_user_current_count(u.__name__)) > 0
381 ]
382 total_miss = sum(miss for _, miss in fixed_users_missing)
383 fixed_users_gen = _kl_generator(fixed_users_missing) # type: ignore[arg-type]
384 # https://mypy.readthedocs.io/en/stable/common_issues.html#variance
385 for _ in range(total_miss):
386 yield next(fixed_users_gen)
387 else:
388 yield next(weighted_users_gen)
389
390 @staticmethod
391 def _fast_users_on_workers_copy(users_on_workers: dict[str, dict[str, int]]) -> dict[str, dict[str, int]]:

Callers 3

__init__Method · 0.95
new_dispatchMethod · 0.95
_distribute_usersMethod · 0.95

Calls 2

_kl_generatorFunction · 0.85

Tested by

no test coverage detected