Message332151
On Linux, posix_spawn() uses vfork() instead of fork() which blocks
the parent process. The child process executes exec() early and so we
don't pay the price of duplicating the memory pages (the thing which
tracks memory pages of a process).
On macOS, posix_spawn() is a system call, so the kernel is free to use
fast-paths to optimize it as they want.
posix_spawn() is faster but it's also safer: it allows us to do a lot of
"actions" before exec(), before executing the new program. For
example, you can close files and control signals. Again, on macOS,
these actions are "atomic" since it's a system call. On Linux, glibc uses a very good implementation which has no race condition.
Currently, Python uses a C extension _posixsubprocess which more or
less reimplements posix_spawn(): close file descriptors, make some
file descriptors inheritable or not, etc. It is very tricky to write
correct code: code run around fork() is very fragile. In theory, the
POSIX specification only allows to use "async-signal-safe" functions
after fork()...
So it would be great to avoid _posixsubprocess whenever possible for
(1) speed (2) correctness. |
|
Date |
User |
Action |
Args |
2018-12-19 16:47:59 | nanjekyejoannah | set | recipients:
+ nanjekyejoannah, vstinner |
2018-12-19 16:47:59 | nanjekyejoannah | set | messageid: <1545238079.48.0.788709270274.issue35537@psf.upfronthosting.co.za> |
2018-12-19 16:47:59 | nanjekyejoannah | link | issue35537 messages |
2018-12-19 16:47:59 | nanjekyejoannah | create | |
|