Python and Django OperationalError (2006, 'MySQL server has gone away')

后端 未结 12 1739
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 15:25

Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought

12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 16:22

    This might be due to DB connections getting copied in your child threads from the main thread. I faced the same error when using python's multiprocessing library to spawn different processes. The connection objects are copied between processes during forking and it leads to MySQL OperationalErrors when making DB calls in the child thread.

    Here's a good reference to solve this: Django multiprocessing and database connections

提交回复
热议问题