Python uselect.POLLOUT Examples
The following are 9
code examples of uselect.POLLOUT().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
uselect
, or try the search function
.
Example #1
Source File: client_w.py From micropython-samples with MIT License | 6 votes |
def run(): global success ok = True try: while ok: res = poller.ipoll(10) for sock, ev in res: if ev & select.POLLOUT: r = sock.send(b'0123456789\n') print(ev, r) # On ESP8266 if another task closes the socket the poll object # never triggers. uasyncio expects it to trigger with POLLHUP or # (POLLOUT & POLLERR or POLLOUT & POLLHUP) # If server fails gets OSError on both platforms. else: # But on Unix socket closure produces ev == 32 print('Terminating event:', ev) # What is 32?? ok = False break await asyncio.sleep(1) await asyncio.sleep(0) except OSError: print('Got OSError') # Happens on ESP8266 if server fails success = True # Detected socket closure or error by OSError or event
Example #2
Source File: __init__.py From uPyCam with Apache License 2.0 | 5 votes |
def add_writer(self, sock, cb, *args): if DEBUG and __debug__: log.debug("add_writer%s", (sock, cb, args)) if args: self.poller.register(sock, select.POLLOUT) self.objmap[id(sock)] = (cb, args) else: self.poller.register(sock, select.POLLOUT) self.objmap[id(sock)] = cb
Example #3
Source File: __init__.py From micropython-samples with MIT License | 5 votes |
def add_writer(self, sock, cb, *args): if DEBUG and __debug__: log.debug("add_writer%s", (sock, cb, args)) if args: self.poller.register(sock, select.POLLOUT) self.objmap[id(sock)] = (cb, args) else: self.poller.register(sock, select.POLLOUT) self.objmap[id(sock)] = cb
Example #4
Source File: __init__.py From microdot with MIT License | 5 votes |
def add_writer(self, sock, cb, *args): if DEBUG and __debug__: log.debug("add_writer%s", (sock, cb, args)) if args: self.poller.register(sock, select.POLLOUT) self.objmap[id(sock)] = (cb, args) else: self.poller.register(sock, select.POLLOUT) self.objmap[id(sock)] = cb
Example #5
Source File: __init__.py From pysmartnode with MIT License | 5 votes |
def add_writer(self, sock, cb, *args): if DEBUG and __debug__: log.debug("add_writer%s", (sock, cb, args)) if args: self.poller.register(sock, select.POLLOUT) self.objmap[id(sock)] = (cb, args) else: self.poller.register(sock, select.POLLOUT) self.objmap[id(sock)] = cb
Example #6
Source File: __init__.py From micropython-async with MIT License | 5 votes |
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
Example #7
Source File: __init__.py From micropython-async with MIT License | 5 votes |
def remove_writer(self, sock): if DEBUG and __debug__: log.debug("remove_writer(%s)", sock) self._unregister(sock, self.wrobjmap, select.POLLOUT)
Example #8
Source File: __init__.py From microhomie with MIT License | 5 votes |
def add_writer(self, sock, cb, *args): if DEBUG and __debug__: log.debug("add_writer%s", (sock, cb, args)) if args: self.poller.register(sock, select.POLLOUT) self.objmap[id(sock)] = (cb, args) else: self.poller.register(sock, select.POLLOUT) self.objmap[id(sock)] = cb
Example #9
Source File: __init__.py From micropython-async with MIT License | 4 votes |
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)