My Django unit tests to validate the behavior of my application when multiple clients access it at the same time:
from django.test import TestCase
from django.db import connection
from django.db import transaction
class ApplicationTestCase(TestCase):
def test_parallel(self):
@transaction.atomic
def local_provision(i):
with connection.cursor() as cursor:
# Some SQL commands that read and write the person table.
# These commands take less than one second.
return f"done with {i}"
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
futures = [executor.submit(local_provision, i) for i in range(5)]
for future in concurrent.futures.as_completed(futures):
print(future.result())
I get:
django.db.utils.OperationalError: database table is locked: person
Changing the timeout in settings.py did not make any difference. Why isn't SQLite waiting until the file is unlocked and then retrying? How can I get SQLite to retry?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745602992a4635511.html
评论列表(0条)