Answer the question
In order to leave comments, you need to log in
How to work with peewee from multiple threads?
Good day.
There is a multi-threaded application using peewee from several threads. Some time after launch, the following exception is thrown:
peewee.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")
from threading import Lock
database_locker = Lock()
database_locker.acquire(blocking=True)
pass #работа с БД
database_locker.release()
Answer the question
In order to leave comments, you need to log in
If anyone is interested, you can pass an argument to database.__init__ threadlocals=True
, which seems to fix everything. As I said, the error does not appear immediately, so you have to wait a bit before you say for sure :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question