Django 1.5用psycopg2抛出随机错误

时间:2013-06-13 14:19:39

标签: python django psycopg2 gunicorn

我遇到了一些奇怪的问题。当我为我的django应用程序运行单个工作程序时?像这样:

python manage.py run_gunicorn -w 1
python manage.py runserver

所有请求都正确提供,但如果启动多个工作人员,请执行以下操作:

python manage.py run_gunicorn -w 10

Django对我的一半请求回复错误:

2013-06-13 18:02:39 [10205] [ERROR] Error handling request
Traceback (most recent call last):
  File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle_request
    for item in respiter:
  File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/raven/middleware.py", line 27, in __call__
    iterable = self.application(environ, start_response)
  File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 255, in __call__
    response = self.get_response(request)
  File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 177, in get_response
    signals.got_request_exception.send(sender=self.__class__, request=request)
  File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 170, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/__init__.py", line 68, in _rollback_on_exception
    transaction.rollback_unless_managed(using=conn)
  File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/transaction.py", line 143, in rollback_unless_managed
    connection.rollback_unless_managed()
  File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 232, in rollback_unless_managed
    self._rollback()
  File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 59, in _rollback
    return self.connection.rollback()
OperationalError: no connection to the server

我尝试使用sqlite3作为Django的DB后端,它运行正常。有人对psycopg2有同样的问题吗?

Django==1.5
gunicorn==0.17.2
psycopg2==2.5

1 个答案:

答案 0 :(得分:0)

抱歉令人不安。 psycopg / Django / gunicorn中没有问题。我使用Nose进行测试:

==== settings.py ====
INSTALLED_APPS = INSTALLED_APPS + ('django_nose',)
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = ['--with-doctest']

删除此行后,随机错误消失。