Persistent variable in subprocess using multiprocessing?

mheavner miheavner at gmail.com
Wed Jul 15 15:55:56 EDT 2009


I'm using multiprocessing to spawn several subprocesses, each of which
uses a very large data structure (making it impractical to pass it via
pipes / pickling). I need to allocate this structure once when the
process is created and have it remain in memory for the duration of
the process. The way the multiprocessing module is set up, only the
'run' method runs within the subprocess - so creating a wrapper class
with a constructor that allocates the structure in __init__ will not
work, as far as I know, as this will still be within the parent
process.

If I were working in C/C++, I would declare the variable "static"
within the function body - is there any way with the multiprocessing
module to have persistent data members within subprocesses?

Any ideas??

Thanks,
   Matt



More information about the Python-list mailing list