File: fork.rst

package info (click to toggle)
python-eventlet 0.40.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 3,200 kB
  • sloc: python: 25,101; sh: 78; makefile: 31
file content (30 lines) | stat: -rw-r--r-- 1,470 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fork() without execve()
=======================

``fork()`` is a way to make a clone of a process.
Most subprocesses replace the child process with a new executable, wiping out all memory from the parent process.
A ``fork()ed`` subprocess can choose not to do this, and preserve data from the parent process.
(Technically this is ``fork()`` without ``execve()``.)

This is a terrible idea, as it can cause deadlocks, memory corruption, and crashes.

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.
This is even more so when using the ``asyncio`` hub, as that requires even more questionable interventions to "work".

This is not a problem with Eventlet.
It's a fundamental problem with ``fork()`` applicable to pretty much every Python program.

Below are some common reasons you might be using ``fork()`` without knowing it, and what you can do about it.

``multiprocessing``
------------------

On Linux, on Python 3.13 earlier, the standard library ``multiprocessing`` library uses ``fork()`` by default.
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>`.


``oslo.service``
----------------

There are alternative ways of running services that do not use ``fork()``.
See the documentation.