Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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()?

like image 290
zer0stimulus Avatar asked Jan 31 '26 02:01

zer0stimulus


2 Answers

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.

like image 21
Winston Ewert Avatar answered Feb 01 '26 15:02

Winston Ewert