Python / Django 1.5 DatabaseWrapper thread error

Throw the following DatabaseError in Django 1.5.1 (and 1.5.0) and mysql when I start the server and try to load the local version of the web application:

DatabaseError in /

DatabaseWrapper objects created in the stream can only be used on this same thread. An object with the alias 'default' was created in stream identifier 4365488128, and this is stream identifier 140735183980896.

The exception location is as follows:

/Users/USERNAME/.envs/PROJECT_NAME/lib/python2.7/site-packages/django/db/backends/ INIT .py in validate_thread_sharing, line 154

This only happens when the first page loads. When I click update, the web application loads as expected. The error is returned when I modify the Django / python code and the local server needs to be re-checked. When this happens, the first load throws DatabaseError again and the subsequent loads again.

This problem only occurs in my Django 1.5 projects. I uninstalled mysql and cleared the mysql binaries located in / usr / local / var / mysql. A new mysql installation did not solve this problem.

A similar DatabaseError is discussed here, but I cannot execute their solution:

https://code.djangoproject.com/ticket/17998

I do not understand here, any ideas or experience will be appreciated. Thanks.

+4
source share
2 answers

I solved the problem by fixing monkeys before importing django. *:

import eventlet eventlet.monkey_patch() 

You understand that I'm using themes here.

+4
source

This is for 1.4, but the cause of the problem may be the same as yours:

https://bitbucket.org/akoha/django-digest/issue/10/conflict-with-global-databasewrapper

Two possible solutions in this post, although both are workarounds:

"I was able to fix this problem by commenting on close_connection in db.py"

"One fix that will definitely work is to replace MultiDb / get_default_db () / self.db with django.db.connection and django.db.tranasction, as described in: https://docs.djangoproject.com/en/dev / topics / db / sql / # executing-custom-sql-directly "

+1
source

All Articles