0

First of all, I'm pretty new in multiprocessing and I'm here for learning of all of you. I have several files doing something similar to this:

SharedClass.py:

class simpleClass():
    a   = 0
    b   = ""
    .....

MyProcess.py:

import multiprocessing
import SharedClass
class FirstProcess(multiprocessing.Process):
    def __init__(self):
    multiprocessing.Process.__init__(self)

    def modifySharedClass():
        # Here I want to modify the object shared with main.py defined in SharedClass.py

Main.py:

from MyProcess  import FirstProcess
import sharedClass
if __name__ == '__main__':
    pr = FirstProcess()
    pr.start()
    # Here I want to print the initial value of the shared class
    pr.modifySharedClass()
    # Here I want to print the modified value of the shared class

I want to define a shared class (in SharedClass.py), in a kind of shared memory that can be readed and writted for both files Main.py and MyProcess.py.

I have try to use the Manager of multiprocessing and multiprocessing.array but Im not having good results, the changes made in one file are not beeing reflected in the other file (maybe Im doing this in the wrong way).

Any ideas? Thank you.

Keles
  • 369
  • 1
  • 2
  • 14
  • "any ideas?" share as little as possible between processes. If you're on *nix and can use "fork" it's easy to share read-only data, but shared mutable data is complicated and slow. the exception being `shared_memory.SharedMemory`, which can only handle binary buffers like numpy arrays. those are at least fast and efficient, but they are somewhat complicated to do correctly – Aaron Mar 23 '21 at 04:23
  • Thanks. I try that but Im not able to make an implementation. – Keles Mar 23 '21 at 13:26

0 Answers0