Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/philipn/green-monkey
Use green versions of all possible modules. For use with gevent.
https://github.com/philipn/green-monkey
Last synced: 24 days ago
JSON representation
Use green versions of all possible modules. For use with gevent.
- Host: GitHub
- URL: https://github.com/philipn/green-monkey
- Owner: philipn
- License: mit
- Created: 2012-03-25T10:40:42.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2012-04-08T23:18:53.000Z (almost 13 years ago)
- Last Synced: 2024-11-07T13:07:47.318Z (3 months ago)
- Language: Python
- Homepage:
- Size: 102 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
green-monkey
============Use green versions of all possible modules. For use with gevent.
.. image:: http://mathburritos.org/misc/greenmonkey2.png
Install & Usage
---------------``pip install green-monkey`` or, from source, ``python setup.py
install``In addition to installing ``green_monkey``, this will install green versions
of all possible modules.Then place the following::
import green_monkey
green_monkey.patch_all()somewhere *before* any of your normal imports or code.
You'll now be using green versions of all modules and the standard
library will be patched. You can think of this as an extension of
``monkey.patch_all()`` beyond the standard library.Example: greening Django project
--------------------------------For instance, in a standard WSGI handler for Apache you might do something
like this::import os, sys
sys.path.append('/usr/local/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'import green_monkey
green_monkey.patch_all()
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()Or in a Gunicorn config, you might do something like this::
bind = "127.0.0.1:"
workers = 3
worker_class = "gevent"
def def_post_fork(server, worker):
import green_monkey
green_monkey.patch_all()
post_fork = def_post_forkand now your Django project is *probably* green!
In general, it's not possible to automatically green an arbitrary
codebase, as it may do something like call an external C library which
blocks. But for many projects this will work well -- *especially* for largely
self-contained bits of code, e.g. event handlers in ``django-socketio``.