2013-06-04 4 views
1

J'essaie d'exécuter mon application Django sur un serveur gunicorn en utilisant gevent. Au sein de mon gunicorn.conf, je monkeypatched tout:Django s'exécutant sur gevent avec pymysql: ImportError

def on_starting(server): 
    from gevent import monkey 
    monkey.patch_socket() 

def post_fork(server, worker): 
    import pymysql 
    pymysql.install_as_MySQLdb() 

MISE À JOUR: J'utilise Django 1.5 avec pymysql 0,5

Maintenant, quand je lance Django je reçois l'exception suivante:

ImportError at/
Exception Value: cannot import name SERVER_STATUS 
Exception Location: /var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/pymysql/connections.py in <module>, line 37 

C'est le retraçage:

File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 
    92.      response = middleware_method(request) 
File "/var/www/myproject/myproject/myapp/middleware.py" in process_request 
    91.    if not request.session.get('language_code', False): 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in get 
    57.   return self._session.get(key, default) 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in _get_session 
    168.     self._session_cache = self.load() 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in load 
    18.     expire_date__gt=timezone.now() 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/db/models/manager.py" in get 
    143.   return self.get_query_set().get(*args, **kwargs) 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/db/models/query.py" in get 
    382.   num = len(clone) 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/db/models/query.py" in __len__ 
    90.     self._result_cache = list(self.iterator()) 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/db/models/query.py" in iterator 
    301.   for row in compiler.results_iter(): 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter 
    775.   for rows in self.execute_sql(MULTI): 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql 
    839.   cursor = self.connection.cursor() 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/db/backends/__init__.py" in cursor 
    324.    cursor = self.make_debug_cursor(self._cursor()) 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py" in _cursor 
    405.    self.connection = Database.connect(**kwargs) 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/MySQLdb/__init__.py" in Connect 
    80.  from MySQLdb.connections import Connection 
File "/var/www/virtualenvs/myproject/local/lib/python2.7/site-packages/pymysql/connections.py" in <module> 
    37. from constants import SERVER_STATUS 

Je ne comprends pas pourquoi je ne suis pas en mesure d'importer SERVER_STATU S ici. Ce fichier existe et à l'intérieur de "python manage.py shell" je suis capable d'importer ce fichier. C'est à dire "à partir de pymysql.constants import SERVER_STATUS" fonctionne.

Des conseils? Je pourrais imaginer que c'est un bogue vraiment stupide ...

Merci d'avance!

Répondre

0

Essayez de déplacer les éléments suivants:

import pymysql 
pymysql.install_as_MySQLdb() 

à settings.py

Questions connexes