Multiprocessing Gevent Extension
Project description
Problem
Due to internal implementation, multiprocessing (MP) is unsafe to use with Gevent even when monkey-patched. Namely, the use of OS semaphore primitives and inter-process IO in MP will cause the main loop to stall/deadlock/block (specific issue depends on the version of CPython).
Solution
GeventMP (Gee-vent Em-Pee) is a gevent multiprocessing extension plugin for the monkey-patching subsystem. As with the rest of the monkey patch subsystem the process is fairly clear:
Identify all places where blocking occurs and where it may stall the loop.
If blocking occurs on a file descriptor (FD), try to convert the file descriptor from blocking to non-blocking (sockets/pipes/fifos, sometimes even files where, rarely, appropriate) and replace blocking IO functions with their gevent non-blocking equivalents.
If blocking occurs in a Python/OS primitive that does not support non-blocking access and thus cannot be geventized, wrap all blocking access to that primitive with native thread-pool-based wrappers and call it a day (while fully understanding that primitive access latency will increase and raw performance may suffer as a result).
If you are really brave and have lots of free time on your hands, completely replace a standard blocking Python non-FD-based primitive with implementation based on an FD-based OS primitive (e.g. POSIX semaphore => Linux eventfd-based semaphore for kernels > 2.6.30).
Due to launching of separate processes in MP, figure out how, when, and whether to monkey-patch spawned/forked children and grandchildren.
Installation
The package is hosted on PyPi.
For stable version:
pip install geventmp
For unstable version:
pip install --pre geventmp
Once installed, GeventMP will activate by default in the below stanza.
from gevent.monkey import patch_all
patch_all()
If you would like GeventMP to not activate by default, either do not install it or explicitly disable it:
from gevent.monkey import patch_all
patch_all(geventmp=False)
That’s it - there are no other flags, settings, properties or config values so far.
Supported Platforms
Linux and Darwin.
CPython 3.9, 3.10, 3.11, 3.12, 3.13
PyPy 3.9, 3.10
Known Issues
Multiprocessing forkserver works in GeventMP, but the spawned child isn’t green.
TODO
Monkey patch Windows to the extent possible.
Lots of applications use Billiard for multiprocessing instead of stock Python package. Consider monkey patching Billiard if detected.
Contact Us
Post feedback and issues on the Bug Tracker, Gitter, and Twitter (@karelleninc).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file geventmp-0.0.9.dev20241029005104.tar.gz
.
File metadata
- Download URL: geventmp-0.0.9.dev20241029005104.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92dd0f3d1dacc810f50cfa6f7f4130c9ae1f2dfc8b940e0c06aaf8a232ce29ba |
|
MD5 | 92bfaec0df71bd6239c03adb04799d98 |
|
BLAKE2b-256 | 85d6e3a1c6b2af8f5f52d08c636e12afe211beaf880937f7f57abb53e2129d5d |
File details
Details for the file geventmp-0.0.9.dev20241029005104-py3-none-any.whl
.
File metadata
- Download URL: geventmp-0.0.9.dev20241029005104-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 569dee7664b131e2cb41002a7795b96de08fb0749be9195c3fee957f912c8a63 |
|
MD5 | 85a39b5dac1f8d8009344a1e925b9464 |
|
BLAKE2b-256 | 2f3c1b5ccbdc2c76a7a3cc2675d4405fe0b384d091be14d38fb0a440e798bca0 |