Closed mmalka87 closed 2 years ago
in the meantime (until i get a reply) i tried this:
from contextlib import asynccontextmanager
database = Database(cfg.MYSQL_CONNECTION_PATH)
@asynccontextmanager
async def connect(transaction=False):
async with database as _database:
try:
await _database.connect()
if transaction:
async with database.connection() as connection:
async with connection.transaction():
yield
else:
yield
except Exception as exc:
logger.exception('Failed to connect to db')
raise
finally:
await database.disconnect()
will try to update here if this works
for anyone landing here...i changed my backend engine to aiomysql (was asyncmy) and added this code:
try:
await database.connect()
... # my code
finally:
await database.disconnect()
Python: 3.10 Databases: 0.5.5 Database backend: MySQL
getting this error after ~8 hours of service running:
i am using Ormar as my ORM and databases to connect to my db (MySQL) and asyncmy as my driver. this is my code for the file base.py:
and this is (part of) my code for the file core.py:
what am i missing? why do i get this error? do i need to reconnnect explicitly before every query? it says in your docs:
full stack trace: