Some issues about "(2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))"
Peewees pool and database implementation rely on connection-per-thread. This works well with regular python and gevent, but not with asyncio. Asyncio needs "connection per asyncio context" or behind a thread pool. > Peewees pool and database implementation rely on connection-per-thread. This works well with regular python and gevent, but not with asyncio. Asyncio needs "connection per asyncio context" or behind a thread pool.

Well......is there any idea to avoid this problem? asyncio is really important in FastAPI...... @czf0613 If your particular use case really needs async, I think you'll have to use sqlalchemy instead of peewee. 

However, for the most applications, async python will not run faster than sync python. If your use case doesn't require async, you can use FastAPI in regular mode by not defining your functions as async def if I remember correctly.


I am using FastAPI as my backend framework.
And I also noticed this problem solution in chatpter "framework integration", which shows:

``` python
# This hook ensures that a connection is opened to handle any queries
# generated by the request.
@app.on_event("startup")
def startup():
    db.connect()


# This hook ensures that the connection is closed when we've finished
# processing the request.
@app.on_event("shutdown")
def shutdown():
    if not db.is_closed():
        db.close()
```

I followed this instruction but still get the same error, "peewee.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))")". I also get another error like "peewee.InterfaceError: (0, '')".

Did I make any mistakes? Maybe it's not compatible with connection pool?
Here is the piece of code that I configure the database:
```python
from playhouse.pool import PooledMySQLDatabase

db = PooledMySQLDatabase(
    'xxxx',
    max_connections=32,
    stale_timeout=60,
    user='xxxxxxxxxxxxx',
    password='xxxxxxxxxxx',
    host='xxxxxxxx',
    port=3306,
    charset='utf8'
)

class BaseModel(Model):
    class Meta:
        database = db
```

Looking forward to your reply, thanks a million!