Closed kien5436 closed 4 months ago
You’re using an asyncio framework so you’ll need to do something like context local database connections. The thread local ones peewee uses aren’t compatible. Here’s some old docs for fastapi which describe the process: https://fastapi.tiangolo.com/how-to/sql-databases-peewee/
I suggest using flask instead.
https://charlesleifer.com/blog/asyncio/ for a little more background.
You’re using an asyncio framework so you’ll need to do something like context local database connections. The thread local ones peewee uses aren’t compatible. Here’s some old docs for fastapi which describe the process: https://fastapi.tiangolo.com/how-to/sql-databases-peewee/
I suggest using flask instead.
This is my company's product so change the framework is risk. I'll try your suggestion
The docs says:
I followed your instruction to create and close connection on each request. However, sometimes I got error "connection already opened". If I use
I get another error "mysql server has gone away".
Here's my config:
Peewee: latest Python: 3.11 OS: Ubuntu 22.04