本文整理匯總了Python中uselect.POLLHUP屬性的典型用法代碼示例。如果您正苦於以下問題:Python uselect.POLLHUP屬性的具體用法?Python uselect.POLLHUP怎麽用?Python uselect.POLLHUP使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類uselect
的用法示例。
在下文中一共展示了uselect.POLLHUP屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: wait
# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLHUP [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)
# Remove "if res" workaround after
# https://github.com/micropython/micropython/issues/2716 fixed.
if res:
for sock, ev in res:
cb = self.objmap[id(sock)]
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:
cb.pend_throw(None)
self.call_soon(cb)
示例2: read
# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLHUP [as 別名]
def read(self):
poll_events = self.poll.poll(0)
if not poll_events:
return
# Check the flag for connection hung up
if poll_events[0][1] & uselect.POLLHUP:
self.client_close = True
msg_bytes = None
try:
msg_bytes = self.ws.read()
except OSError:
self.client_close = True
# If no bytes => connection closed. See the link below.
# http://stefan.buettcher.org/cs/conn_closed.html
if not msg_bytes or self.client_close:
raise ClientClosedError()
return msg_bytes
示例3: wait
# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLHUP [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)
# Remove "if res" workaround after
# https://github.com/micropython/micropython/issues/2716 fixed.
if res:
for sock, ev in res:
cb = self.objmap[id(sock)]
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:
cb.pend_throw(None)
self.call_soon(cb)
示例4: add_reader
# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLHUP [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
示例5: add_writer
# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLHUP [as 別名]
def add_writer(self, sock, cb, *args):
if DEBUG and __debug__:
log.debug("add_writer%s", (sock, cb, args))
# HACK Should read
# self._register(sock, select.POLLOUT)
# 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.POLLOUT | select.POLLHUP | select.POLLERR) # t35tB0t add HUP and ERR to force LWIP revents
if args:
self.wrobjmap[id(sock)] = (cb, args)
else:
self.wrobjmap[id(sock)] = cb
示例6: wait
# 需要導入模塊: import uselect [as 別名]
# 或者: from uselect import POLLHUP [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)