Skip to main content
Gitter Build Status Coverage Status

GeventMP Version GeventMP Python Versions GeventMP Downloads Per Day GeventMP Downloads Per Week GeventMP Downloads Per Month

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:

  1. Identify all places where blocking occurs and where it may stall the loop.

  2. 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.

  3. 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).

  4. 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).

  5. 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.10, 3.11, 3.12, 3.13, 3.14, 3.15

TODO

  1. Monkey patch Windows to the extent possible.

  2. 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).

Metadata

Release files for geventmp 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for geventmp 0.0.11
File Size Uploaded
geventmp-0.0.11.tar.gz 17.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for geventmp 0.0.11
File Interpreter ABI Platform
geventmp-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 39.7 kB

Release files / geventmp-0.0.11.tar.gz

Download URL geventmp-0.0.11.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
65483615f39830ee26bef5f1c1d2700a38711a68830b7a0df1a1bfeef4cefb0e
BLAKE2b-256 checksum
How to use checksums
7332ac2437a017b7d492c3cd8bb45c777cc0c0ba4b962bc6458a616a90dd5ae6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / geventmp-0.0.11-py3-none-any.whl

Download URL geventmp-0.0.11-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
351b9ab7392c07597c07490aedf4af94538a500b8cdf213a7e9b32943660857e
BLAKE2b-256 checksum
How to use checksums
46c73d12748d20959e7b03670395e26b45649abb4359d4835d9bc2196c5a21cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page