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


Python select.epoll方法代碼示例

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


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

示例1: _can_allocate

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

示例2: DefaultSelector

# 需要導入模塊: import select [as 別名]
# 或者: from select import epoll [as 別名]
def DefaultSelector():
    """This function serves as a first call for DefaultSelector to detect.

    It is for when the select module is being monkey-patched incorrectly by eventlet, greenlet,
    and preserve proper behavior.
    """
    global _DEFAULT_SELECTOR
    if _DEFAULT_SELECTOR is None:
        if _can_allocate('kqueue'):
            _DEFAULT_SELECTOR = KqueueSelector
        elif _can_allocate('epoll'):
            _DEFAULT_SELECTOR = EpollSelector
        elif _can_allocate('poll'):
            _DEFAULT_SELECTOR = PollSelector
        elif hasattr(select, 'select'):
            _DEFAULT_SELECTOR = SelectSelector
        else:  # Platform-specific: AppEngine
            raise ValueError('Platform does not have a selector')
    return _DEFAULT_SELECTOR() 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:21,代碼來源:ssl_wrap_util.py

示例3: _can_allocate

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

示例4: DefaultSelector

# 需要導入模塊: import select [as 別名]
# 或者: from select import epoll [as 別名]
def DefaultSelector():
    """ This function serves as a first call for DefaultSelector to
    detect if the select module is being monkey-patched incorrectly
    by eventlet, greenlet, and preserve proper behavior. """
    global _DEFAULT_SELECTOR
    if _DEFAULT_SELECTOR is None:
        if _can_allocate('kqueue'):
            _DEFAULT_SELECTOR = KqueueSelector
        elif _can_allocate('epoll'):
            _DEFAULT_SELECTOR = EpollSelector
        elif _can_allocate('poll'):
            _DEFAULT_SELECTOR = PollSelector
        elif hasattr(select, 'select'):
            _DEFAULT_SELECTOR = SelectSelector
        else:  # Platform-specific: AppEngine
            raise ValueError('Platform does not have a selector')
    return _DEFAULT_SELECTOR() 
開發者ID:getavalon,項目名稱:core,代碼行數:19,代碼來源:selectors.py

示例5: __init__

# 需要導入模塊: import select [as 別名]
# 或者: from select import epoll [as 別名]
def __init__(self):
        if hasattr(select, 'epoll'):
            self._impl = select.epoll()
            model = 'epoll'
        elif hasattr(select, 'kqueue'):
            self._impl = KqueueLoop()
            model = 'kqueue'
        elif hasattr(select, 'select'):
            self._impl = SelectLoop()
            model = 'select'
        else:
            raise Exception('can not find any available functions in select '
                            'package')
        self._fdmap = {}  # (f, handler)
        self._last_time = time.time()
        self._periodic_callbacks = []
        self._stopping = False
        logging.debug('using event model: %s', model) 
開發者ID:ntfreedom,項目名稱:neverendshadowsocks,代碼行數:20,代碼來源:eventloop.py

示例6: test_fromfd

# 需要導入模塊: import select [as 別名]
# 或者: from select import epoll [as 別名]
def test_fromfd(self):
        server, client = self._connected_pair()

        ep = select.epoll(2)
        ep2 = select.epoll.fromfd(ep.fileno())

        ep2.register(server.fileno(), select.EPOLLIN | select.EPOLLOUT)
        ep2.register(client.fileno(), select.EPOLLIN | select.EPOLLOUT)

        events = ep.poll(1, 4)
        events2 = ep2.poll(0.9, 4)
        self.assertEqual(len(events), 2)
        self.assertEqual(len(events2), 2)

        ep.close()
        try:
            ep2.poll(1, 4)
        except IOError, e:
            self.assertEqual(e.args[0], errno.EBADF, e) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_epoll.py

示例7: poll

# 需要導入模塊: import select [as 別名]
# 或者: from select import epoll [as 別名]
def poll(self, timeout):
        try:
            r, w, e = select.select(self._r, self._w, [], timeout)
        except select.error as err:
            if err.errno == errno.EINTR:
                return
            raise

        smap_get = self.socket_map.get
        for fd in r:
            obj = smap_get(fd)
            if obj is None or not obj.readable():
                continue
            _read(obj)
        for fd in w:
            obj = smap_get(fd)
            if obj is None or not obj.writable():
                continue
            _write(obj)


# ===================================================================
# --- poll() / epoll()
# =================================================================== 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:26,代碼來源:ioloop.py

示例8: initialize

# 需要導入模塊: import select [as 別名]
# 或者: from select import epoll [as 別名]
def initialize(self, **kwargs):
        super(EPollIOLoop, self).initialize(impl=select.epoll(), **kwargs) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:4,代碼來源:epoll.py

示例9: __init__

# 需要導入模塊: import select [as 別名]
# 或者: from select import epoll [as 別名]
def __init__(self):
            super(EpollSelector, self).__init__()
            self._epoll = select.epoll() 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:5,代碼來源:ssl_wrap_util.py

示例10: select

# 需要導入模塊: import select [as 別名]
# 或者: from select import epoll [as 別名]
def select(self, timeout=None):
            if timeout is not None:
                if timeout <= 0:
                    timeout = 0.0
                else:
                    # select.epoll.poll() has a resolution of 1 millisecond
                    # but luckily takes seconds so we don't need a wrapper
                    # like PollSelector. Just for better rounding.
                    timeout = math.ceil(timeout * 1e3) * 1e-3
                timeout = float(timeout)
            else:
                timeout = -1.0  # epoll.poll() must have a float.

            # We always want at least 1 to ensure that select can be called
            # with no file descriptors registered. Otherwise will fail.
            max_events = max(len(self._fd_to_key), 1)

            ready = []
            fd_events = _syscall_wrapper(self._epoll.poll, True,
                                         timeout=timeout,
                                         maxevents=max_events)
            for fd, event_mask in fd_events:
                events = 0
                if event_mask & ~select.EPOLLIN:
                    events |= EVENT_WRITE
                if event_mask & ~select.EPOLLOUT:
                    events |= EVENT_READ

                key = self._key_from_fd(fd)
                if key:
                    ready.append((key, events & key.events))
            return ready 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:34,代碼來源:ssl_wrap_util.py


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