Share an attribute of Singleton class across all child processes without passing it as a function argument

Viewed 13

I have a Singleton class and I want to share an attribute of that Singleton class across all processes without passing it through a function argument as a shared variable.

Sample code given below:

class Singleton():
   abc = {}
   def __call__():
      abc['key'] = ".com"

class myClass(metaclass=Singleton):
   def capslock(name):
      print name.upper()

if __name__==__main__:
   import multiprocessing as mp
   process1 = mp.Process(target=myClass.capslock, args=("stackoverflow"))

   process1.start()
   process1.join()

For the print statement, I need name.upper() + abc['key] but all the child processes will have the Singleton attribute empty.

0 Answers
Related