git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pymysql.err.InterfaceError after some hours of usage


?? ???????, 2 ????????? 2019 - 7:11:52 ?.?. UTC+3, ? ??????? Inada Naoki ??????:
> 2019?10?3?(?) 0:56 ????? ?????? <vergos.nikolas at gmail.com>:
> 
> > ?? ???????, 2 ????????? 2019 - 8:26:38 ?.?. UTC+3, ? ??????? Inada Naoki
> > ??????:
> > > MySQL connection can be closed automatically by various reasons.
> > > For example, `wait_timeout` is the most common but not only reason for
> > > closing the connection.
> > >
> > > You should connect and close MySQL connection for each HTTP request.
> > >
> > > Or you can use more smart connection pool (e.g. Engine in SQLAlchemy).
> > > It provides `pool_recycle` and `pool_pre_ping` options.
> > >
> > > https://docs.sqlalchemy.org/en/13/core/pooling.html#setting-pool-recycle
> >
> > You mean that every time i insrt/update and in general having a
> > cur.execute() i then need to close the pymysql connection in order to not
> > have this error?
> >
> 
> No, I meant one new DB connection for each HTTP request, not for each DB
> query.

After seeing a stackoverflow link, it was stating that:

This is caused by a global cursor. Try creating and closing the cursor within each method a raw query is needed.

cursor = connection.cursor() cursor.execute(query) cursor.close()

Does that mean that i have to create a cursor then execute the SQL statement and the close the cursor? And i must do that before and after executing each SQL statement in all of my scripts?

Doesn't the DB Connection have a directive to autoclose the resources?