Async Fork
This module implements a simple os.fork()
-like interface,
but in an asynchronous way with full support for PID file descriptors
on Python 3.9 or higher and the Linux kernel 5.4 or higher.
It internally synchronizes the beginning and readiness status of child processes
so that the users may assume that the child process is completely interruptible after
afork()
returns.
- class AbstractChildProcess[source]
The abstract interface to control and monitor a forked child process.
- PosixChildProcess(pid: int) None [source]
A POSIX-compatible version of
AbstractChildProcess
.
- PidfdChildProcess(pid: int, pidfd: int) None [source]
A PID file descriptor-based version of
AbstractChildProcess
.
- async afork(child_func: Callable[[], int]) aiotools.fork.AbstractChildProcess [source]
Fork the current process and execute the given function in the child. The return value of the function will become the exit code of the child process.
- Parameters
child_func – A function that represents the main function of the child and returns an integer as its exit code. Note that the function must set up a new event loop if it wants to run asyncio codes.