当我使用self.engine.dispose()
时这是我的代码它给了我Exception,所以如果我使用它del self.engine
它工作正常,请给我任何建议。
class MSSqlAlchemyConn(object):
def __init__(self, connection_obj):
"""
Constructor for SQLAlchemy.
"""
try:
# connection string
# example: mysql+mysqldb://[mysqluser]:[password]@[host]:[port]/[db_name]
constr = "mssql+pymssql://%s:%s@%s/%s" % (connection_obj['USER'], connection_obj['PASSWORD'],
connection_obj['HOST'],
connection_obj['DATABASE'])
self.engine = create_engine(constr, echo=False)
except Exception as e:
logger.error(e)
def __del__(self):
if self.engine is not None:
del self.engine