django - How do I get parallel access to retry on "database table is locked" error? - Stack Overflow

My Django unit tests to validate the behavior of my application when multiple clients access it at the

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

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信