Solve Django OperationalError: (2013, ‘Lost connection to MySQL server during query’)


I got this errors when running my scripts that using multiprocessing to speed-up the task.

1
OperationalError: (2013, ‘Lost connection to MySQL server during query’)

Apparently, this problems occurs because another process try to open database connection that already opened by Django.
To solve this problem, just close django database connection in your target worker function with:

1
2
from django import db
db.close_connection()

One response to “Solve Django OperationalError: (2013, ‘Lost connection to MySQL server during query’)”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.