| 1 |
fork() without execve() |
| 2 |
======================= |
| 3 |
|
| 4 |
``fork()`` is a way to make a clone of a process. |
| 5 |
Most subprocesses replace the child process with a new executable, wiping out all memory from the parent process. |
| 6 |
A ``fork()ed`` subprocess can choose not to do this, and preserve data from the parent process. |
| 7 |
(Technically this is ``fork()`` without ``execve()``.) |
| 8 |
|
| 9 |
This is a terrible idea, as it can cause deadlocks, memory corruption, and crashes. |
| 10 |
|
| 11 |
For backwards compatibility, Eventlet *tries* to work in this case, but this is very much not guaranteed and your program may suffer from deadlocks, memory corruption, and crashes. |
| 12 |
This is even more so when using the ``asyncio`` hub, as that requires even more questionable interventions to "work". |
| 13 |
|
| 14 |
This is not a problem with Eventlet. |
| 15 |
It's a fundamental problem with ``fork()`` applicable to pretty much every Python program. |
| 16 |
|
| 17 |
Below are some common reasons you might be using ``fork()`` without knowing it, and what you can do about it. |
| 18 |
|
| 19 |
``multiprocessing`` |
| 20 |
------------------ |
| 21 |
|
| 22 |
On Linux, on Python 3.13 earlier, the standard library ``multiprocessing`` library uses ``fork()`` by default. |
| 23 |
To fix this, switch to the ``"spawn"`` method (the default in Python 3.14 and later) as `documented here <https://docs.python.org/3.13/library/multiprocessing.html#contexts-and-start-methods>`. |
| 24 |
|
| 25 |
|
| 26 |
``oslo.service`` |
| 27 |
---------------- |
| 28 |
|
| 29 |
There are alternative ways of running services that do not use ``fork()``. |
| 30 |
See the documentation. |