If this needs to be cross-platform, then no, you cannot share a list like this. (On Unix, if you're careful, you sometimes can, but never on Windows.)
If you read Sharing state between processes in the documentation, it explains what you can share and how, but basically, it's just simple values, Array
s of other shareable types, and anything you can define as a ctypes.Structure
, and that's it.
The Programming guidelines, especially the Windows section, explains why this is true, and how you can deal with it. But basically, the problem is that, on Windows, the new process is not a fork of the old one, it's a brand-new process.
There are many alternatives.
The best is usually to redesign your algorithm around passing immutable values to the child and having it return new immutable values, instead of mutating shared values.
If you can't go that far, you can usually rewrite things in terms of passing messages over, e.g., a Queue
or a Pipe
. In the worst case, the messages can be (list.append, data, [10, 14, 5])
, but usually you can come up with something higher-level and more meaningful than that.