I have been running an Django 1.5.1 app under Apache for some time without 
issue. Today, without any changes to the server I started seeing 500 Errors 
caused by an Exception in DatabaseWrapper relating to threading, I have no 
threading behavior in my code so this confuses me. The error affects all 
routes, although intermittently, roughly every 10th access or so hit this 
problem. It seems to trigger on first contact with the Database (Postgres 9.2 
running on another machine)

Some tracebacks don't touch any of my own code. I restarted Apache and it made 
no difference, then I stopped Apache completely and started it again, now I am 
no longer seeing the error. However i'd like to understand why this happened 
and prevent it from happening again.

Any suggestions on what may have caused this?

Thanks,
Fraser Graham

An example traceback from one of the API calls:

Traceback (most recent call last):

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/tastypie/resources.py",
 line 217, in wrapper
   response = callback(request, *args, **kwargs)

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/tastypie/resources.py",
 line 468, in dispatch_detail
   return self.dispatch('detail', request, **kwargs)

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/tastypie/resources.py",
 line 486, in dispatch
   self.is_authenticated(request)

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/tastypie/resources.py",
 line 569, in is_authenticated
   auth_result = self._meta.authentication.is_authenticated(request)

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/tastypie/authentication.py",
 line 490, in is_authenticated
   check = backend.is_authenticated(request, **kwargs)

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/tastypie/authentication.py",
 line 194, in is_authenticated
   user = User.objects.get(**lookup_kwargs)

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/django/db/models/manager.py",
 line 143, in get
   return self.get_query_set().get(*args, **kwargs)

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/django/db/models/query.py",
 line 382, in get
   num = len(clone)

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/django/db/models/query.py",
 line 90, in __len__
   self._result_cache = list(self.iterator())

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/django/db/models/query.py",
 line 301, in iterator
   for row in compiler.results_iter():

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
 line 775, in results_iter
   for rows in self.execute_sql(MULTI):

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/django/db/models/sql/compiler.py",
 line 839, in execute_sql
   cursor = self.connection.cursor()

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/django/db/backends/__init__.py",
 line 321, in cursor
   self.validate_thread_sharing()

 File 
"/home/bats/.virtualenvs/bats/lib/python2.7/site-packages/django/db/backends/__init__.py",
 line 154, in validate_thread_sharing
   % (self.alias, self._thread_ident, thread.get_ident()))

DatabaseError: DatabaseWrapper objects created in a thread can only be used in 
that same thread. The object with alias 'default' was created in thread id 
140625758729984 and this is thread id 140625691588352.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/BF827916-9A90-467D-9624-F57CBE65BF49%40me.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to