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


Python uselect.POLLIN屬性代碼示例

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


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

示例1: run

# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLIN [as 別名]
def run():
    global success
    ok = True
    try:
        while ok:
            res = poller.ipoll(10)
            for sock, ev in res:
                if ev & select.POLLIN:
                    r = sock.readline()
                    print(ev, r)
                    # A server outage prints 1, b'' forever on ESP8266 or Unix.
                    # If killer closes socket on ESP8266 ev is always 1,
                    # on Unix get ev == 32
                    # Never see 9 or 17 (base 10) which are the error responses expected by uasyncio
                    # (POLLIN & POLLERR or POLLIN & POLLHUP)
                else:  # The only way I can make it work (on Unix) is to quit on 32
                    print('Terminating event:', ev)  # What is 32??
                    ok = False
                    break
            await asyncio.sleep(0)
    except OSError:
        print('Got OSError')  # Never happens
    success = True  # Detected socket closure or error by OSError or event 
開發者ID:peterhinch,項目名稱:micropython-samples,代碼行數:25,代碼來源:client_r.py

示例2: run

# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLIN [as 別名]
def run(self, loop, port=8123):
        addr = socket.getaddrinfo('0.0.0.0', port, 0, socket.SOCK_STREAM)[0][-1]
        s_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # server socket
        s_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        s_sock.bind(addr)
        s_sock.listen(5)
        self.socks = [s_sock]  # List of current sockets for .close()
        print('Awaiting connection on port', port)
        poller = select.poll()
        poller.register(s_sock, select.POLLIN)
        client_id = 1  # For user feedback
        while True:
            res = poller.poll(1)  # 1ms block
            if res:  # Only s_sock is polled
                c_sock, _ = s_sock.accept()  # get client socket
                loop.create_task(self.run_client(c_sock, client_id))
                client_id += 1
            await asyncio.sleep_ms(200) 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:20,代碼來源:userver.py

示例3: add_reader

# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLIN [as 別名]
def add_reader(self, sock, cb, *args):
        if DEBUG and __debug__:
            log.debug("add_reader%s", (sock, cb, args))
        if args:
            self.poller.register(sock, select.POLLIN)
            self.objmap[id(sock)] = (cb, args)
        else:
            self.poller.register(sock, select.POLLIN)
            self.objmap[id(sock)] = cb 
開發者ID:lemariva,項目名稱:uPyCam,代碼行數:11,代碼來源:__init__.py

示例4: add

# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLIN [as 別名]
def add(self, target, socket=None):
        if not socket:
            socket = target.sockets()
        if self.use_poll:
            self.poller.register(socket, select.POLLIN)
        # dbg("add device on fileno: %s" % socket.fileno() )
        self.targets[socket.fileno()] = target
        # dbg("size targets: %s" % len(self.targets)) 
開發者ID:lemariva,項目名稱:uPyEcho,代碼行數:10,代碼來源:main.py

示例5: run

# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLIN [as 別名]
def run(expected, verbose=False, port=8123, timeout=2000):
    addr = socket.getaddrinfo('0.0.0.0', port, 0, socket.SOCK_STREAM)[0][-1]
    s_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  # server socket
    s_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s_sock.bind(addr)
    s_sock.listen(len(expected) + 2)
    verbose and print('Awaiting connection.', port)
    poller = select.poll()
    poller.register(s_sock, select.POLLIN)
    to_secs = timeout / 1000  # ms -> secs
    while True:
        res = poller.poll(1)  # 1ms block
        if res:  # Only s_sock is polled
            c_sock, _ = s_sock.accept()  # get client socket
            c_sock.setblocking(False)
            try:
                data = await _readid(c_sock, to_secs)
            except OSError:
                c_sock.close()
            else:
                Connection.go(to_secs, data, verbose, c_sock, s_sock,
                              expected)
        await asyncio.sleep(0.2)


# A Connection persists even if client dies (minimise object creation).
# If client dies Connection is closed: ._close() flags this state by closing its
# socket and setting .sock to None (.status() == False). 
開發者ID:peterhinch,項目名稱:micropython-iot,代碼行數:30,代碼來源:server.py

示例6: __init__

# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLIN [as 別名]
def __init__(self, addr, s, close_callback):
        self.client_close = False
        self._need_check = False

        self.address = addr
        self.socket = s
        self.ws = websocket(s, True)
        self.poll = uselect.poll()
        self.close_callback = close_callback

        self.socket.setblocking(False)
        self.poll.register(self.socket, uselect.POLLIN) 
開發者ID:BetaRavener,項目名稱:upy-websocket-server,代碼行數:14,代碼來源:ws_connection.py

示例7: _check_new_connections

# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLIN [as 別名]
def _check_new_connections(self, accept_handler):
        poll_events = self._listen_poll.poll(0)
        if not poll_events:
            return

        if poll_events[0][1] & uselect.POLLIN:
            accept_handler() 
開發者ID:BetaRavener,項目名稱:upy-websocket-server,代碼行數:9,代碼來源:ws_server.py

示例8: add_reader

# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLIN [as 別名]
def add_reader(self, sock, cb, *args):
        if DEBUG and __debug__:
            log.debug("add_reader%s", (sock, cb, args))
        # HACK This should read
        # self._register(sock, select.POLLIN)
        # Temporary workround for https://github.com/micropython/micropython/issues/5172
        # The following is not compliant with POSIX or with the docs
        self._register(sock, select.POLLIN | select.POLLHUP | select.POLLERR)  # t35tB0t add HUP and ERR to force LWIP revents
        if args:
            self.rdobjmap[id(sock)] = (cb, args)
        else:
            self.rdobjmap[id(sock)] = cb 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:14,代碼來源:__init__.py

示例9: remove_reader

# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLIN [as 別名]
def remove_reader(self, sock):
        if DEBUG and __debug__:
            log.debug("remove_reader(%s)", sock)
        self._unregister(sock, self.rdobjmap, select.POLLIN) 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:6,代碼來源:__init__.py

示例10: wait

# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLIN [as 別名]
def wait(self, delay):
        if DEBUG and __debug__:
            log.debug("poll.wait(%d)", delay)
        # We need one-shot behavior (second arg of 1 to .poll())
        res = self.poller.ipoll(delay, 1)
        #log.debug("poll result: %s", res)
        for sock, ev in res:
            if ev & select.POLLOUT:
                cb = self.wrobjmap[id(sock)]
                if cb is None:
                    continue  # Not yet ready.
                # Invalidate objmap: can get adverse timing in fast_io whereby add_writer
                # is not called soon enough. Ignore poll events occurring before we are
                # ready to handle them.
                self.wrobjmap[id(sock)] = None
                if ev & (select.POLLHUP | select.POLLERR):
                    # These events are returned even if not requested, and
                    # are sticky, i.e. will be returned again and again.
                    # If the caller doesn't do proper error handling and
                    # unregister this sock, we'll busy-loop on it, so we
                    # as well can unregister it now "just in case".
                    self.remove_writer(sock)
                if DEBUG and __debug__:
                    log.debug("Calling IO callback: %r", cb)
                if isinstance(cb, tuple):
                    cb[0](*cb[1])
                else:
                    prev = cb.pend_throw(None)  # Enable task to run.
                    #if isinstance(prev, Exception):
                        #print('Put back exception')
                        #cb.pend_throw(prev)
                    self._call_io(cb)  # Put coro onto runq (or ioq if one exists)
            if ev & select.POLLIN:
                cb = self.rdobjmap[id(sock)]
                if cb is None:
                    continue
                self.rdobjmap[id(sock)] = None
                if ev & (select.POLLHUP | select.POLLERR):
                    # These events are returned even if not requested, and
                    # are sticky, i.e. will be returned again and again.
                    # If the caller doesn't do proper error handling and
                    # unregister this sock, we'll busy-loop on it, so we
                    # as well can unregister it now "just in case".
                    self.remove_reader(sock)
                if DEBUG and __debug__:
                    log.debug("Calling IO callback: %r", cb)
                if isinstance(cb, tuple):
                    cb[0](*cb[1])
                else:
                    prev = cb.pend_throw(None)  # Enable task to run.
                    #if isinstance(prev, Exception):
                        #cb.pend_throw(prev)
                        #print('Put back exception')
                    self._call_io(cb) 
開發者ID:peterhinch,項目名稱:micropython-async,代碼行數:56,代碼來源:__init__.py


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