I have a singleton class which I use. I make an instance of this class on my Main Thread.
I Create a few multi-processes and what seems logical (due to how the GIL works) to me is that when I instantiate the same class there its a new instance, it cannot see the one instantiated at my Main Thread.
But if I do the same on Linux, when creating my multi-processes and instantiate my class it returns the pointer to the instance created at my Main Thread and can thus see the data from that one.
This might be touching on some basic principle of threading in both Linux and Windows I do not understand. But if someone could help me briefly to understand or point to where I can read about it
Regards
EDIT
On Windows:
def child_process_function():
SingletonThread = instantiate_singleton() <-- This will be a new instance
do_work()
SingletonMain = instantiate_singleton()
process = multiprocessing.Process(target=child_process_function)
process.start()
On Linux
def child_process_function():
SingletonThread = instantiate_singleton() <-- This will contain the data from the SingletonMain.
do_work()
SingletonMain = instantiate_singleton()
process = multiprocessing.Process(target=child_process_function)
process.start()
Now after reading your link the Linux SingletonThread does not point to the SingletonMain as I thought at first its simply just data copied. However my problem is that because the data does not get copied on windows I send the data through a Queue (The data changes all the time so this is the desired method). However there is a Overwrite block on the class (it contains settings) so if the data is already there as on Linux I get and write error on the class. However adding the.
import multiprocessing as mp
mp.set_start_method('spawn')
Fixes my problem.