开发者

python: what happens when an object is passed in multiprocessing.Process?

p = Process(target=f, args=(myObject,))
p.start()
p.join()

From experimentation, inside of function f(), I can access myObject fine and its members appears to be intact, even though presumably we're in 开发者_如何转开发a different process. Printing id(myObject) in the current function and in f() returns the same number.

Is Python secretly performing IPC when myObject is accessed inside of f()?


As Winston wrote: on Unix the process will be forked and the forked process is basically a full copy of the parent process (that's why the id is identical).


The actual process depends on whether you are running unix or windows.

On *nix, fork() is used which creates a complete copy of your process.

On windows, I believe the object is pickled (see the pickle module) and sent over some IPC channel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜