3

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.

Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382

1 Answers1

2

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".

hynekcer
  • 14,942
  • 6
  • 61
  • 99
  • 1
    @MridangAgarwalla: The recently mentioned promissing fix that I have seen is in 1.0 series https://bitbucket.org/denis/gevent/ . The same day has been released 0.13.7 but the changeset of 0.13 series does not look so promissing. I read a blog about gevent + django. Simimar problems in discussion had been fixed by upgrading. If your problem is different, can it be easy reproduced? – hynekcer Apr 14 '12 at 22:42
  • @JustinPoliey: I am afraid that completition to satisfaction would require your feedback. Django can work with gevent. An example is this blog http://codysoyland.com/2011/feb/6/evented-django-part-one-socketio-and-gevent/ Can you be more specific? It's not much time. – hynekcer Apr 15 '12 at 12:06