Skip to main content

Make C module compatible with gevent at runtime.

Project description

greenify can make Python extension modules having network operations in C code to be compatible with gevent.

greenify uses the Dynamic Function Redirecting technique same as ELF-Hook to patch blocking network operations at runtime, without the need modify the original modules.

Currently greenify only supports ELF format modules, and is tested on Linux.

Build status

  • Branch master : travis_master

Install from source

greenify module is installed using setuptools or pip:

python setup.py install

or:

pip install greenify

Usage

  1. Active greenify before initiate environment:

    import greenify
    greenify.greenify()
  2. Make sure the dynamic module(e.g. libmemcached) is patched before using:

    assert greenify.patch_lib('/usr/lib/libmemcached.so')
  3. Import and use the corresponding module, which is now gevent compatible.

Thread Safety

Once activated, the green C functions will, on potentially blocking operation, pass control to gevent’s main event loop, which may switch to other ready greenlet which is also in one of the green functions. So, make sure your C code can handle this kind of execution pause and resume. A thread safe program usually is ready for greenify, but remember that all the switches happen in a single thread.

License

greenify is written and maintained by douban and is licensed under New BSD license.

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

greenify-0.3.3.tar.gz (10.4 kB view hashes)

Uploaded Source

Built Distributions

greenify-0.3.3-cp35-cp35m-manylinux2010_x86_64.whl (138.4 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

greenify-0.3.3-cp35-cp35m-manylinux1_x86_64.whl (138.4 kB view hashes)

Uploaded CPython 3.5m

greenify-0.3.3-cp27-cp27mu-manylinux2010_x86_64.whl (127.3 kB view hashes)

Uploaded CPython 2.7mu manylinux: glibc 2.12+ x86-64

greenify-0.3.3-cp27-cp27mu-manylinux1_x86_64.whl (127.3 kB view hashes)

Uploaded CPython 2.7mu

greenify-0.3.3-cp27-cp27m-manylinux2010_x86_64.whl (127.3 kB view hashes)

Uploaded CPython 2.7m manylinux: glibc 2.12+ x86-64

greenify-0.3.3-cp27-cp27m-manylinux1_x86_64.whl (127.3 kB view hashes)

Uploaded CPython 2.7m

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