Python sqlalchemy.pool 模块,Pool() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用sqlalchemy.pool.Pool()

项目:airflow    作者:apache-airflow    | 项目源码 | 文件源码
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()
项目:tornadopy    作者:xubigshu    | 项目源码 | 文件源码
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()