简体   繁体   中英

Gevent exceptions in Django when patching Python modules

I have installed the gevent and greenlet libraries and in the __init__.py file of my Djano application I dumped in these two lines:

from gevent import monkey
monkey.patch_all()

Now it's very often I see errors in my Django console that read:

Exception KeyError: KeyError(27066240,) in <module 'threading' from 'C:\Program_Files\Python27\Lib\threading.pyc'> ignored

When I remove those two lines, my application works just fine. Here's a list of the packages I'm using on my Windows machine.

django-erroneous - 0.1.0       - active
Django          - 1.3.1        - active
gevent          - 0.13.6       - active
greenlet        - 0.3.3        - active
lxml            - 2.3.3        - active
PIL             - 1.1.7        - active
pip             - 1.0.2        - active
setuptools      - 0.6c11       - active
South           - 0.7.3        - active
virtualenv      - 1.6.1        - active
yolk            - 0.4.1        - active

Are there some compatibility issues with Django and Gevent? Am I doing something wrong here.

FYI, I'm using the pre-built Windows binaries from the unofficial Python repository and this is a development environment.

Yesterday has been fixed a bug in monkey module related to patch_item . Any further testing is recommended with the fixed version.

If it does not help, you can make the problem narrower by calling patch_all with some arguments set to False and find which module is the problematic for you.

def patch_all(socket=True, dns=True, time=True, select=True, thread=True, os=True, ssl=True, httplib=False, aggressive=True)

The first what I eventually recommend to test narrower is monkey.patch_all(socket=False, select=False) . This makes "dns" and "aggressive" to be unused also. Than you can concentrate on socket and select separately and finally, if everything other can be safely enabled, on playing with "dns" and "aggressive".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM