我正在关闭会话,但连接仍然在MySQL中睡眠了大约一个小时。问题是,我有太多的连接睡眠后,一段时间。我使用Python3、PyMySQL 1.0.2和SQLAlchemy 2.0.0编写以下代码。
import pymysql.cursors
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
connect_string = f"mysql+pymysql://{db_user}@/{db_name}?unix_socket=/cloudsql/{cloudsql_instance}"
engine = create_engine(connect_string, echo=False, pool_recycle=30,pool_size=20, max_overflow=0)
session = sessionmaker(expire_on_commit=True, autoflush=True, autocommit=False)
session.configure(bind=engine())
session = session()
all_users = session.execute(text('SELECT employee_name FROM users WHERE status='1';')).fetchall()
print(all_users)
session.close()
字符串
1条答案
按热度按时间hgc7kmma1#
最后添加这一行
个字符