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.9, 3.10, 3.11, 3.12, 3.13

  • PyPy 3.9, 3.10

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.10.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

geventmp-0.0.10-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file geventmp-0.0.10.tar.gz.

File metadata

  • Download URL: geventmp-0.0.10.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for geventmp-0.0.10.tar.gz
Algorithm Hash digest
SHA256 b2da8a73412c756d9b9fc0a64e3d02a2eb329c15618e13874c34dcd1531fdbb6
MD5 787fb8d0ded8f633e033fe2bbd175493
BLAKE2b-256 3d9d455c007a0ff07f7387bae3ab733aa1d4c59bc200c2f5cb228fc25c193cd7

See more details on using hashes here.

File details

Details for the file geventmp-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: geventmp-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 22.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for geventmp-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 940f367d2e34eaac99e9b10ab813d881b9d1908834e0490fa17dd3dd565a27dc
MD5 57707e2cf19df67f36fc6b614cc37cae
BLAKE2b-256 5e166a86bb1129c10a6b7ef1dc292ea6f6c340ea0d5969a0ff1538d9de64f4a2

See more details on using hashes here.

Supported by

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