我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用sqlalchemy.pool.Pool()。
def pessimistic_connection_handling(): @event.listens_for(Pool, "checkout") def ping_connection(dbapi_connection, connection_record, connection_proxy): ''' Disconnect Handling - Pessimistic, taken from: http://docs.sqlalchemy.org/en/rel_0_9/core/pooling.html ''' cursor = dbapi_connection.cursor() try: cursor.execute("SELECT 1") except: raise exc.DisconnectionError() cursor.close()
def connection_event(): @event.listens_for(Pool, "checkout") def ping_connection(dbapi_connection, connection_record, connection_proxy): # ?????????????????????????? # ???????????????????? cursor = dbapi_connection.cursor() try: cursor.execute("SELECT 1") except: SysLogger.error('database pool has gone away') connection_proxy._pool.dispose() cursor.close()