1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Accessing any object type from multiprocessing shared_memory?

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    Suppose I create a shared memory object:

    from multiprocessing import shared_memory
    shm_a = shared_memory.SharedMemory(create=True, size=1024)
    buffer = shm_a.buf


    and put a generic object of a generic class, such as:

    class GenericClass:
    def __init__(self, a, b):
    self.a = a
    self.b = b


    in it:

    gen_obj_a = GenericClass(1,6)
    buffer = gen_obj_a


    Now, in another terminal, I have:

    from multiprocessing import shared_memory
    existing_shm = shared_memory.SharedMemory(name='psm_21467_46075')


    How do I assign a variable, say gen_obj_b, to the GenericClass object in shared memory?

    In C++, one would do this by casting a void * to the GenericClass object type, but how is this done in Python with shared memory?

    cf. multiprocessing.shared_memory Python documentation

    Continue reading...

Compartilhe esta Página