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 2.7, 3.5, 3.6, 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.1.tar.gz (16.1 kB view details)

Uploaded Source

Built Distributions

geventmp-0.0.1-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

geventmp-0.0.1-py2-none-any.whl (21.8 kB view details)

Uploaded Python 2

File details

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

File metadata

  • Download URL: geventmp-0.0.1.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for geventmp-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3d62e79ef7ec8a9a490d60cd06fa48c5d6ff2bf68abb45033e62454c0a84c854
MD5 9b7a9c0f72c45418abd8c75d962f17ef
BLAKE2b-256 a45083e5646ed280c83d08a713e2d6894a75d7e9088c142fb669372b042d6ffe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: geventmp-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for geventmp-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f6098e3c4d6f6105b71e37a3184cec79f63f9f9b590d3a7844f3d37993b2db6
MD5 65ff0f2d1e09a7f6bb032c0baf0f4300
BLAKE2b-256 9b845df2197ffc3fc8cb5841244aff5872543d143e50171787dd5860cb32e2e6

See more details on using hashes here.

File details

Details for the file geventmp-0.0.1-py2-none-any.whl.

File metadata

  • Download URL: geventmp-0.0.1-py2-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/2.7.18

File hashes

Hashes for geventmp-0.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 7c970c17dc1dee5abdb2a0babc4e31a216192adab1b9866e2d8fe6ff0f16af12
MD5 c47cc423888e1a8e4de04ab67a53089c
BLAKE2b-256 40d07f400e73b03daa0a2e32a64c9efd06a7c8f28e585fb681e21b9a5cb1abdf

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