multiprocessing module backport from 3 to 2.7 - spawn feature

Andres Riancho andres.riancho at gmail.com
Wed Jan 28 14:04:29 EST 2015


On Wed, Jan 28, 2015 at 3:06 PM, Skip Montanaro
<skip.montanaro at gmail.com> wrote:
>
> On Wed, Jan 28, 2015 at 7:07 AM, Andres Riancho <andres.riancho at gmail.com>
> wrote:
>>
>> The feature I'm specially interested in is the ability to spawn
>> processes [1] instead of forking, which is not present in the 2.7
>> version of the module.
>
>
> Can you explain what you see as the difference between "spawn" and "fork" in
> this context?

Well, fork is a system call [0] where a process creates a copy of
itself, usually using COW [1]. This copy receives a new process ID and
is slightly dependent on the parent: they share the same address
space.

Spawn, and I took that from the multiprocessing 3 documentation, will
create a new process without using fork(). This means that no memory
is shared between the MainProcess and the spawn'ed sub-process created
by multiprocessing.

My goal is to prevent dead-locks and other issues [2][3] which come
from forking a multithreaded program (situation I'm in right now).

[0] https://en.wikipedia.org/wiki/Fork_%28system_call%29
[1] https://en.wikipedia.org/wiki/Copy-on-write
[2] See "Note that safely forking a multithreaded process is
problematic." at
https://docs.python.org/3.4/library/multiprocessing.html#multiprocessing.set_start_method
[3] http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them

> Are you using Windows perhaps? I don't know anything obviously
> different between the two terms on Unix systems.

Nope, I'm on linux

> Skip
>



-- 
Andrés Riancho
Project Leader at w3af - http://w3af.org/
Web Application Attack and Audit Framework
Twitter: @w3af
GPG: 0x93C344F3



More information about the Python-list mailing list