Skip to main content

Multiprocessing Gevent Extension

Project description

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.7, 3.8, 3.9, 3.10, 3.11, 3.12

  • PyPy 3.8, 3.9

Known Issues

  • Multiprocessing forkserver works in GeventMP, but the spawned child isn’t green.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

geventmp-0.0.8.dev20230711180108.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

geventmp-0.0.8.dev20230711180108-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file geventmp-0.0.8.dev20230711180108.tar.gz.

File metadata

File hashes

Hashes for geventmp-0.0.8.dev20230711180108.tar.gz
Algorithm Hash digest
SHA256 7729951fb8203cb2ef4bba33b235fca4c9ca1ec3b00728f450492423a10b7671
MD5 247a9e438806157c482a6fe93a34120f
BLAKE2b-256 8ee80182ad98b5cacfb4feb4c318fd949eb448f6093a1b94bb4666305625e111

See more details on using hashes here.

File details

Details for the file geventmp-0.0.8.dev20230711180108-py3-none-any.whl.

File metadata

File hashes

Hashes for geventmp-0.0.8.dev20230711180108-py3-none-any.whl
Algorithm Hash digest
SHA256 648ede01289ab88b732cc8b3b86f0f80d7f8a303fdf03e7040ffd8acf65dd230
MD5 d089234d2148f00594a8c43d170baf2b
BLAKE2b-256 69e8cd5f9e87eac51da5194dd9984c6414f6f950e5853fb0bea57c20537ee841

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page