當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。