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)
| 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 |