當前位置: 首頁>>代碼示例>>Python>>正文


Python select.POLLIN屬性代碼示例

本文整理匯總了Python中select.POLLIN屬性的典型用法代碼示例。如果您正苦於以下問題:Python select.POLLIN屬性的具體用法?Python select.POLLIN怎麽用?Python select.POLLIN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在select的用法示例。


在下文中一共展示了select.POLLIN屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _parse_events

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def _parse_events(self, events):
        """Parse ``events``.

        ``events`` is a list of events as returned by
        :meth:`select.poll.poll()`.

        Yield all parsed events.

        """
        for fd, event_mask in events:
            if self._has_event(event_mask, select.POLLNVAL):
                raise IOError('File descriptor not open: {0!r}'.format(fd))
            elif self._has_event(event_mask, select.POLLERR):
                raise IOError('Error while polling fd: {0!r}'.format(fd))

            if self._has_event(event_mask, select.POLLIN):
                yield fd, 'r'
            if self._has_event(event_mask, select.POLLOUT):
                yield fd, 'w'
            if self._has_event(event_mask, select.POLLHUP):
                yield fd, 'h' 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:23,代碼來源:poll.py

示例2: run

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def run(self):
        #print(self.run, 'enter')
        while True:
            #print(self.run, 'cycle')
            pollret = dict(self.pollobj.poll()).get(self.fileno, 0)
            if pollret & POLLNVAL != 0:
                break
            if pollret & POLLIN == 0:
                continue
            try:
                clientsock, addr = self.clicm.serversock.accept()
            except Exception as why:
                if isinstance(why, socket.error):
                    if why.errno == ECONNABORTED:
                        continue
                    elif why.errno == EBADF:
                        break
                    else:
                        raise
                dump_exception('CLIConnectionManager: unhandled exception when accepting incoming connection')
                break
            #print(self.run, 'handle_accept')
            ED2.callFromThread(self.clicm.handle_accept, clientsock, addr)
        self.clicm = None
        #print(self.run, 'exit') 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:27,代碼來源:CLIManager.py

示例3: poll_wait_for_socket

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def poll_wait_for_socket(sock, read=False, write=False, timeout=None):
    if not read and not write:
        raise RuntimeError("must specify at least one of read=True, write=True")
    mask = 0
    if read:
        mask |= select.POLLIN
    if write:
        mask |= select.POLLOUT
    poll_obj = select.poll()
    poll_obj.register(sock, mask)

    # For some reason, poll() takes timeout in milliseconds
    def do_poll(t):
        if t is not None:
            t *= 1000
        return poll_obj.poll(t)

    return bool(_retry_on_intr(do_poll, timeout)) 
開發者ID:danielecook,項目名稱:gist-alfred,代碼行數:20,代碼來源:wait.py

示例4: _select

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def _select(self):
    with self._lock:
      fds = self._file_descriptors
      fd_to_callback = self._file_descriptor_to_callback
    if fds:
      if _HAS_POLL:
        # With 100 file descriptors, it is approximately 5x slower to
        # recreate and reinitialize the Poll object on every call to _select
        # rather reuse one. But the absolute cost of contruction,
        # initialization and calling poll(0) is ~25us so code simplicity
        # wins.
        poll = select.poll()
        for fd in fds:
          poll.register(fd, select.POLLIN)
        ready_file_descriptors = [fd for fd, _ in poll.poll(1)]
      else:
        ready_file_descriptors, _, _ = select.select(fds, [], [], 1)
      for fd in ready_file_descriptors:
        fd_to_callback[fd]()
    else:
      # select([], [], [], 1) is not supported on Windows.
      time.sleep(1) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:24,代碼來源:wsgi_server.py

示例5: select

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def select(self, timeout=None):
            if timeout is None:
                timeout = None
            elif timeout <= 0:
                timeout = 0
            else:
                # poll() has a resolution of 1 millisecond, round away from
                # zero to wait *at least* timeout seconds.
                timeout = int(math.ceil(timeout * 1e3))
            ready = []
            try:
                fd_event_list = wrap_error(self._poll.poll, timeout)
            except InterruptedError:
                return ready
            for fd, event in fd_event_list:
                events = 0
                if event & ~select.POLLIN:
                    events |= EVENT_WRITE
                if event & ~select.POLLOUT:
                    events |= EVENT_READ

                key = self._key_from_fd(fd)
                if key:
                    ready.append((key, events & key.events))
            return ready 
開發者ID:jpush,項目名稱:jbox,代碼行數:27,代碼來源:selectors.py

示例6: test_poll_blocks_with_negative_ms

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def test_poll_blocks_with_negative_ms(self):
        for timeout_ms in [None, -1000, -1, -1.0]:
            # Create two file descriptors. This will be used to unlock
            # the blocking call to poll.poll inside the thread
            r, w = os.pipe()
            pollster = select.poll()
            pollster.register(r, select.POLLIN)

            poll_thread = threading.Thread(target=pollster.poll, args=(timeout_ms,))
            poll_thread.start()
            poll_thread.join(timeout=0.1)
            self.assertTrue(poll_thread.is_alive())

            # Write to the pipe so pollster.poll unblocks and the thread ends.
            os.write(w, b'spam')
            poll_thread.join()
            self.assertFalse(poll_thread.is_alive())
            os.close(r)
            os.close(w) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_poll.py

示例7: pollmask_to_str

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def pollmask_to_str(mask):
        """
        Conver pool mast to string

        :param mask: poll return mask
        """
        out = ""
        if (mask & select.POLLIN):
            out += "IN "
        if (mask & select.POLLPRI):
            out += "PRI IN "
        if (mask & select.POLLOUT):
            out += "OUT "
        if (mask & select.POLLERR):
            out += "ERR "
        if (mask & select.POLLHUP):
            out += "HUP "
        if (mask & select.POLLMSG):
            out += "MSG "
        return out 
開發者ID:avocado-framework,項目名稱:avocado-vt,代碼行數:22,代碼來源:virtio_console_guest.py

示例8: worker

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def worker(virt):
    """
    Worker thread (infinite) loop of virtio_guest.
    """
    global exiting
    print("PASS: Daemon start.")
    p = select.poll()
    p.register(sys.stdin.fileno())
    while not exiting:
        d = p.poll()
        if (d[0][1] == select.POLLIN):
            out = input()
            try:
                exec(out)
            except Exception:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                print("On Guest exception from: \n" + "".join(
                    traceback.format_exception(exc_type,
                                               exc_value,
                                               exc_traceback)))
                print("FAIL: Guest command exception.")
        elif (d[0][1] & select.POLLHUP):
            time.sleep(0.5) 
開發者ID:avocado-framework,項目名稱:avocado-vt,代碼行數:25,代碼來源:virtio_console_guest.py

示例9: connect

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def connect(self):
        self.s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        self.s.connect(self.spath)
        self.poller = select.poll()
        self.poller.register(self.s, select.POLLIN) 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:7,代碼來源:DNRelay.py

示例10: __init__

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def __init__(self, clicm):
        Thread.__init__(self)
        self.clicm = clicm
        self.pollobj = poll()
        self.fileno = self.clicm.serversock.fileno()
        self.pollobj.register(self.fileno, POLLIN)
        self.setDaemon(True)
        self.start() 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:10,代碼來源:CLIManager.py

示例11: is_connection_dropped

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def is_connection_dropped(conn):  # Platform-specific
    """
    Returns True if the connection is dropped and should be closed.

    :param conn:
        :class:`httplib.HTTPConnection` object.

    Note: For platforms like AppEngine, this will always return ``False`` to
    let the platform handle connection recycling transparently for us.
    """
    sock = getattr(conn, 'sock', False)
    if sock is False:  # Platform-specific: AppEngine
        return False
    if sock is None:  # Connection already closed (such as by httplib).
        return True

    if not poll:
        if not select:  # Platform-specific: AppEngine
            return False

        try:
            return select([sock], [], [], 0.0)[0]
        except socket.error:
            return True

    # This version is better on platforms that support it.
    p = poll()
    p.register(sock, POLLIN)
    for (fno, ev) in p.poll(0.0):
        if fno == sock.fileno():
            # Either data is buffered (bad), or the connection is dropped.
            return True


# This function is copied from socket.py in the Python 2.7 standard
# library test suite. Added to its signature is only `socket_options`. 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:38,代碼來源:connection.py

示例12: register

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def register(self, fileobj, events, data=None):
            key = super(PollSelector, self).register(fileobj, events, data)
            event_mask = 0
            if events & EVENT_READ:
                event_mask |= select.POLLIN
            if events & EVENT_WRITE:
                event_mask |= select.POLLOUT
            self._poll.register(key.fd, event_mask)
            return key 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:11,代碼來源:ssl_wrap_util.py

示例13: select

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def select(self, timeout=None):
            ready = []
            fd_events = _syscall_wrapper(self._wrap_poll, True, timeout=timeout)
            for fd, event_mask in fd_events:
                events = 0
                if event_mask & ~select.POLLIN:
                    events |= EVENT_WRITE
                if event_mask & ~select.POLLOUT:
                    events |= EVENT_READ

                key = self._key_from_fd(fd)
                if key:
                    ready.append((key, events & key.events))

            return ready 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:17,代碼來源:ssl_wrap_util.py

示例14: is_connection_dropped

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def is_connection_dropped(conn):  # Platform-specific
    """
    Returns True if the connection is dropped and should be closed.

    :param conn:
        :class:`httplib.HTTPConnection` object.

    Note: For platforms like AppEngine, this will always return ``False`` to
    let the platform handle connection recycling transparently for us.
    """
    sock = getattr(conn, 'sock', False)
    if sock is False:  # Platform-specific: AppEngine
        return False
    if sock is None:  # Connection already closed (such as by httplib).
        return True

    if not poll:
        if not select:  # Platform-specific: AppEngine
            return False

        try:
            return select([sock], [], [], 0.0)[0]
        except socket.error:
            return True

    # This version is better on platforms that support it.
    p = poll()
    p.register(sock, POLLIN)
    for (fno, ev) in p.poll(0.0):
        if fno == sock.fileno():
            # Either data is buffered (bad), or the connection is dropped.
            return True


# This function is copied from socket.py in the Python 2.7 standard
# library test suite. Added to its signature is only `socket_options`.
# One additional modification is that we avoid binding to IPv6 servers
# discovered in DNS if the system doesn't have IPv6 functionality. 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:40,代碼來源:connection.py

示例15: start

# 需要導入模塊: import select [as 別名]
# 或者: from select import POLLIN [as 別名]
def start(self):
    """Start watching the directory for changes."""
    self._class_setup()

    self._inotify_fd = InotifyFileWatcher._libc.inotify_init()
    if self._inotify_fd < 0:
      error = OSError('failed call to inotify_init')
      error.errno = ctypes.get_errno()
      error.strerror = errno.errorcode[ctypes.get_errno()]
      raise error
    self._inotify_poll = select.poll()
    self._inotify_poll.register(self._inotify_fd, select.POLLIN)
    self._add_watch_for_path(self._directory) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:15,代碼來源:inotify_file_watcher.py


注:本文中的select.POLLIN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。