0
Follow
0
View

How can I handle multiple requests at the same time in Django?

dongabc22 注册会员
2023-01-25 07:49

I'm guessing you're using SQLite database. It doesn't allow concurrent writes, i.e. more than one writing operations at a given time.

You have to options:

  1. Either switch to a different database
  2. Or increase the database timeout option in settings

Example:

# settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'db.sqlite3',
        'OPTIONS': {
            'timeout': 60, # 1 minute
        }
    }
}

This is not a scalable solution. Suppose, you've got many processes waiting for the write access, you may still get OperationalError if there are any processes still waiting after 60 seconds.

About the Author

Question Info

Publish Time
2023-01-25 07:49
Update Time
2023-01-25 07:49