Esempio n. 1
0
 def runner():
     # Passing django.db.connection between threads doesn't work while
     # connections[DEFAULT_DB_ALIAS] does.
     from django.db import connections
     connection = connections[DEFAULT_DB_ALIAS]
     # Allow thread sharing so the connection can be closed by the
     # main thread.
     connection.inc_thread_sharing()
     connection.cursor()
     connections_dict[id(connection)] = connection
Esempio n. 2
0
 def runner():
     # Passing django.db.connection between threads doesn't work while
     # connections[DEFAULT_DB_ALIAS] does.
     from django.db import connections
     connection = connections[DEFAULT_DB_ALIAS]
     # Allow thread sharing so the connection can be closed by the
     # main thread.
     connection.inc_thread_sharing()
     connection.cursor()
     connections_dict[id(connection)] = connection
Esempio n. 3
0
 def test_thread_sharing_count(self):
     self.assertIs(connection.allow_thread_sharing, False)
     connection.inc_thread_sharing()
     self.assertIs(connection.allow_thread_sharing, True)
     connection.inc_thread_sharing()
     self.assertIs(connection.allow_thread_sharing, True)
     connection.dec_thread_sharing()
     self.assertIs(connection.allow_thread_sharing, True)
     connection.dec_thread_sharing()
     self.assertIs(connection.allow_thread_sharing, False)
     msg = "Cannot decrement the thread sharing count below zero."
     with self.assertRaisesMessage(RuntimeError, msg):
         connection.dec_thread_sharing()
Esempio n. 4
0
 def test_thread_sharing_count(self):
     self.assertIs(connection.allow_thread_sharing, False)
     connection.inc_thread_sharing()
     self.assertIs(connection.allow_thread_sharing, True)
     connection.inc_thread_sharing()
     self.assertIs(connection.allow_thread_sharing, True)
     connection.dec_thread_sharing()
     self.assertIs(connection.allow_thread_sharing, True)
     connection.dec_thread_sharing()
     self.assertIs(connection.allow_thread_sharing, False)
     msg = 'Cannot decrement the thread sharing count below zero.'
     with self.assertRaisesMessage(RuntimeError, msg):
         connection.dec_thread_sharing()