MCPcopy
hub / github.com/django/django / validate_thread_sharing

Method validate_thread_sharing

django/db/backends/base/base.py:637–650  ·  view source on GitHub ↗

Validate that the connection isn't accessed by another thread than the one which originally created it, unless the connection was explicitly authorized to be shared between threads (via the `inc_thread_sharing()` method). Raise an exception if the validation fails.

(self)

Source from the content-addressed store, hash-verified

635 self._thread_sharing_count -= 1
636
637 def validate_thread_sharing(self):
638 """
639 Validate that the connection isn't accessed by another thread than the
640 one which originally created it, unless the connection was explicitly
641 authorized to be shared between threads (via the `inc_thread_sharing()`
642 method). Raise an exception if the validation fails.
643 """
644 if not (self.allow_thread_sharing or self._thread_ident == _thread.get_ident()):
645 raise DatabaseError(
646 "DatabaseWrapper objects created in a "
647 "thread can only be used in that same thread. The object "
648 "with alias '%s' was created in thread id %s and this is "
649 "thread id %s." % (self.alias, self._thread_ident, _thread.get_ident())
650 )
651
652 # ##### Miscellaneous #####
653

Callers 11

_prepare_cursorMethod · 0.95
commitMethod · 0.95
rollbackMethod · 0.95
closeMethod · 0.95
savepointMethod · 0.95
savepoint_rollbackMethod · 0.95
savepoint_commitMethod · 0.95
closeMethod · 0.80

Calls 1

DatabaseErrorClass · 0.90