当前位置: 首页>>代码示例>>Python>>正文


Python extensions.POLL_READ属性代码示例

本文整理汇总了Python中psycopg2.extensions.POLL_READ属性的典型用法代码示例。如果您正苦于以下问题:Python extensions.POLL_READ属性的具体用法?Python extensions.POLL_READ怎么用?Python extensions.POLL_READ使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在psycopg2.extensions的用法示例。


在下文中一共展示了extensions.POLL_READ属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wait_select_inter

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import POLL_READ [as 别名]
def wait_select_inter(conn):
    while True:
        try:
            state = conn.poll()
            if state == POLL_OK:
                break
            elif state == POLL_READ:
                select([conn.fileno()], [], [])
            elif state == POLL_WRITE:
                select([], [conn.fileno()], [])
            else:
                raise conn.OperationalError(
                    "bad state from poll: %s" % state)
        except KeyboardInterrupt:
            conn.cancel()
            # the loop will be broken by a server error
            continue 
开发者ID:Yelp,项目名称:mycroft,代码行数:19,代码来源:redshift_psql.py

示例2: wait_select

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import POLL_READ [as 别名]
def wait_select(conn):
    """Wait until a connection or cursor has data available.

    The function is an example of a wait callback to be registered with
    `~psycopg2.extensions.set_wait_callback()`. This function uses
    :py:func:`~select.select()` to wait for data available.

    """
    import select
    from psycopg2.extensions import POLL_OK, POLL_READ, POLL_WRITE

    while 1:
        state = conn.poll()
        if state == POLL_OK:
            break
        elif state == POLL_READ:
            select.select([conn.fileno()], [], [])
        elif state == POLL_WRITE:
            select.select([], [conn.fileno()], [])
        else:
            raise conn.OperationalError("bad state from poll: %s" % state) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:23,代码来源:extras.py

示例3: _wait_select

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import POLL_READ [as 别名]
def _wait_select(conn):
    """
        copy-pasted from psycopg2.extras.wait_select
        the default implementation doesn't define a timeout in the select calls
    """
    while 1:
        try:
            state = conn.poll()
            if state == POLL_OK:
                break
            elif state == POLL_READ:
                select.select([conn.fileno()], [], [], _WAIT_SELECT_TIMEOUT)
            elif state == POLL_WRITE:
                select.select([], [conn.fileno()], [], _WAIT_SELECT_TIMEOUT)
            else:
                raise conn.OperationalError("bad state from poll: %s" % state)
        except KeyboardInterrupt:
            conn.cancel()
            # the loop will be broken by a server error
            continue
        except select.error as e:
            errno = e.args[0]
            if errno != 4:
                raise


# When running a query, make pressing CTRL+C raise a KeyboardInterrupt
# See http://initd.org/psycopg/articles/2014/07/20/cancelling-postgresql-statements-python/
# See also https://github.com/psycopg/psycopg2/issues/468 
开发者ID:dbcli,项目名称:pgcli,代码行数:31,代码来源:pgexecute.py

示例4: wait_select

# 需要导入模块: from psycopg2 import extensions [as 别名]
# 或者: from psycopg2.extensions import POLL_READ [as 别名]
def wait_select(conn):
    """Wait until a connection or cursor has data available.

    The function is an example of a wait callback to be registered with
    `~psycopg2.extensions.set_wait_callback()`. This function uses
    :py:func:`~select.select()` to wait for data available.

    """
    import select
    from psycopg2.extensions import POLL_OK, POLL_READ, POLL_WRITE

    while 1:
        try:
            state = conn.poll()
            if state == POLL_OK:
                break
            elif state == POLL_READ:
                select.select([conn.fileno()], [], [])
            elif state == POLL_WRITE:
                select.select([], [conn.fileno()], [])
            else:
                raise conn.OperationalError("bad state from poll: %s" % state)
        except KeyboardInterrupt:
            conn.cancel()
            # the loop will be broken by a server error
            continue 
开发者ID:tryolabs,项目名称:aws-workshop,代码行数:28,代码来源:extras.py


注:本文中的psycopg2.extensions.POLL_READ属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。