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


Python select.poll方法代碼示例

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


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

示例1: for_events

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [as 別名]
def for_events(cls, *events):
        """Listen for ``events``.

        ``events`` is a list of ``(fd, event)`` pairs, where ``fd`` is a file
        descriptor or file object and ``event`` either ``'r'`` or ``'w'``.  If
        ``r``, listen for whether that is ready to be read.  If ``w``, listen
        for whether the channel is ready to be written to.

        """
        notifier = eintr_retry_call(select.poll)
        for fd, event in events:
            mask = cls._EVENT_TO_MASK.get(event)
            if not mask:
                raise ValueError('Unknown event type: {0!r}'.format(event))
            notifier.register(fd, mask)
        return cls(notifier) 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:18,代碼來源:poll.py

示例2: poll

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [as 別名]
def poll(self, timeout=None):
        """Poll for events.

        ``timeout`` is an integer specifying how long to wait for events (in
        milliseconds).  If omitted, ``None`` or negative, wait until an event
        occurs.

        Return a list of all events that occurred before ``timeout``, where
        each event is a pair ``(fd, event)``. ``fd`` is the integral file
        descriptor, and ``event`` a string indicating the event type.  If
        ``'r'``, there is data to read from ``fd``.  If ``'w'``, ``fd`` is
        writable without blocking now.  If ``'h'``, the file descriptor was
        hung up (i.e. the remote side of a pipe was closed).

        """
        # Return a list to allow clients to determine whether there are any
        # events at all with a simple truthiness test.
        return list(self._parse_events(eintr_retry_call(self._notifier.poll, timeout))) 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:20,代碼來源:poll.py

示例3: _parse_events

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [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

示例4: deliver_dnotify

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [as 別名]
def deliver_dnotify(self, dnstring, _recurse = 0):
        if self.s == None:
            self.connect()
        if _recurse > _MAX_RECURSE:
            raise Exception('Cannot reconnect: %s', self.spath)
        if not dnstring.endswith('\n'):
            dnstring += '\n'
        while True:
            try:
                self.s.send(dnstring)
                break
            except socket.error as why:
                if why[0] == EINTR:
                    continue
                elif why[0] in (EPIPE, ENOTCONN, ECONNRESET):
                    self.s = None
                    return self.deliver_dnotify(dnstring, _recurse + 1)
                raise why
        # Clean any incoming data on the socket
        if len(self.poller.poll(0)) > 0:
            try:
                self.s.recv(1024)
            except:
                pass
        return 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:27,代碼來源:DNRelay.py

示例5: run

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [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

示例6: poll_wait_for_socket

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [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

示例7: _can_allocate

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [as 別名]
def _can_allocate(struct):
    """Checks that select structs can be allocated by the underlying operating system.

    Otherwise it could be just advertised by the select module. We don't check select() because we'll be hopeful
    that most platforms that don't have it available will not advertise it. (ie: GAE).
    """
    try:
        # select.poll() objects won't fail until used.
        if struct == 'poll':
            p = select.poll()
            p.poll(0)

        # All others will fail on allocation.
        else:
            getattr(select, struct)().close()
        return True
    except (OSError, AttributeError):
        return False


# Choose the best implementation, roughly:
# kqueue == epoll > poll > select. Devpoll not supported. (See above)
# select() also can't accept a FD > FD_SETSIZE (usually around 1024) 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:25,代碼來源:ssl_wrap_util.py

示例8: _can_allocate

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [as 別名]
def _can_allocate(struct):
    """ Checks that select structs can be allocated by the underlying
    operating system, not just advertised by the select module. We don't
    check select() because we'll be hopeful that most platforms that
    don't have it available will not advertise it. (ie: GAE) """
    try:
        # select.poll() objects won't fail until used.
        if struct == 'poll':
            p = select.poll()
            p.poll(0)

        # All others will fail on allocation.
        else:
            getattr(select, struct)().close()
        return True
    except (OSError, AttributeError) as e:
        return False


# Choose the best implementation, roughly:
# kqueue == epoll > poll > select. Devpoll not supported. (See above)
# select() also can't accept a FD > FD_SETSIZE (usually around 1024) 
開發者ID:getavalon,項目名稱:core,代碼行數:24,代碼來源:selectors.py

示例9: _select

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [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

示例10: select

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [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

示例11: __init__

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [as 別名]
def __init__(self, host=None, port=0,
                 timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
        """Constructor.

        When called without arguments, create an unconnected instance.
        With a hostname argument, it connects the instance; port number
        and timeout are optional.
        """
        self.debuglevel = DEBUGLEVEL
        self.host = host
        self.port = port
        self.timeout = timeout
        self.sock = None
        self.rawq = ''
        self.irawq = 0
        self.cookedq = ''
        self.eof = 0
        self.iacseq = '' # Buffer for IAC sequence.
        self.sb = 0 # flag for SB and SE sequence.
        self.sbdataq = ''
        self.option_callback = None
        self._has_poll = hasattr(select, 'poll')
        if host is not None:
            self.open(host, port, timeout) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:telnetlib.py

示例12: loop

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [as 別名]
def loop(timeout=30.0, use_poll=False, map=None, count=None):
    if map is None:
        map = socket_map

    if use_poll and hasattr(select, 'poll'):
        poll_fun = poll2
    else:
        poll_fun = poll

    if count is None:
        while map:
            poll_fun(timeout, map)

    else:
        while map and count > 0:
            poll_fun(timeout, map)
            count = count - 1 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:19,代碼來源:asyncore.py

示例13: __init__

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [as 別名]
def __init__(self, notifier):
        """Create a poll object for the given ``notifier``.

        ``notifier`` is the :class:`select.poll` object wrapped by the new poll
        object.

        """
        self._notifier = notifier 
開發者ID:mbusb,項目名稱:multibootusb,代碼行數:10,代碼來源:poll.py

示例14: connect

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [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

示例15: __init__

# 需要導入模塊: import select [as 別名]
# 或者: from select import poll [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


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