connection.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:ibrest 作者: hamx0r 项目源码 文件源码
def get_client():
    """ Creates a client connection to be used with orders
    """
    # Get client ID from our non-order pool list in memory
    timeout = g.timeout
    while g.clientId_in_use:
        log.debug('Waiting for clientId to become available...({})'.format(timeout))
        time.sleep(0.5)
        timeout -= 1

    client = g.client_connection

    # Enable logging if we're in debug mode
    if current_app.debug is True:
        client.enableLogging()

    # Reconnect if needed
    if not client.isConnected():
        log.debug('Client {} not connected.  Trying to reconnect...'.format(g.client_id))
        client.disconnect()
        time.sleep(1)
        client.connect()
        # If we failed to reconnect, be sure to put our client ID back in the pool
        if client.isConnected() is False:
            raise Exception('Client cannot connect')
    return client
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号