title: How to force the race condition in transaction in django tests?
body: <p>Is there a way to run the django tests using multiple threads and force the race condition? I want to make sure that the code path that handles the transaction errors is executed. To be slightly more specific, I want to be able to spawn 2 threads that will try to perform the same action on the database, with one of them succeeding and the other one failing. I am using the test framework that is in django.</p>
  
  <p>Python pseudocode:</p>
  
  <pre><code>def some_method():
    try
      with transaction.atomic():
        objectA = get_object_from_db()
        objectA.delete()
    except Error:
      # error handling code to be run
  
  
  class TestClass(TransactionalTestCase):
    def test_some_method():
      # run two threads and make sure that the race condition was present and some_method recovered successfully
  </code></pre>