python multiprocessing - Best way to initialize/pass database connection to be used across processes python multiprocessing - Best way to initialize/pass database connection to be used across processes database database

python multiprocessing - Best way to initialize/pass database connection to be used across processes


I'm going to go ahead and put my comment up as an answer, because I think it's appropriate as one. You don't want to try to pass database connections from your parent process to your children processes. You want to move static data or other objects that can be serialized to your children processes. You can pass rows of data, etc. Or you want to have your children establish their own database connections when they become necessary.


Try pickling the db connection object. Pickling is independent of processes. So it might work..

Ref these pages - python pickle
pickle examples