[Python] Assign globally-unique user_id to each created User in multi-process setup

Discussão em 'Python' iniciado por Stack, Janeiro 28, 2025.

  1. Stack

    Stack Membro Participativo

    I'm attempting to distribute a list of pre-defined request payloads across all the Users which are spawned in my run. Conceptually I want to split my list of N requests across U Users, such that each request is only issued once to the server.

    For a single process I can achieve this by simply assigning a unique id to each User in the __init__ method - e.g.:

    class MyUser():
    count = 0

    def __init__(self, env):
    super().__init__(environment)
    self.user_id = MyUser.count
    MyUser.count += 1


    However when using multiple processes (via --processes=P) obviously have multiple instances of MyUser.count and hence the user_ids are not unique.

    Is there some kind of centralised mechanism I can use to assign IDs (or some existing unique ID)?

    Continue reading...

Compartilhe esta Página