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, not Gee-ven Tee-Em-Pee) is an extension plugin for monkey patch subsystem of Gevent. 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.6, 3.7, 3.8, 3.9, 3.10

  • PyPy 3.7, 3.8

Known Issues

  • Multiprocessing forkserver works with gevent, 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.2.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

geventmp-0.0.2-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: geventmp-0.0.2.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for geventmp-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4d0b1a243b7262159639ed7d7ecdb66e18f6531e339c8fac5b938137ba989fb9
MD5 c52803749546acb9ead59eeef1b8f520
BLAKE2b-256 7ffc16dc4534748574d588231d70bc38b4b17d93052b1edb771247cc2c2893bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: geventmp-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for geventmp-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 afd6da7f0025badb239531dd8253dce684cfb8990e460f8aca516a459d5564fb
MD5 eaf00562fbcdebdbe3de2a52f05fa5c7
BLAKE2b-256 a698577948c71b8deeb381d32526deaf40420375300992a924635575ad578738

See more details on using hashes here.

Supported by

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