1try: 2 import usocket as socket, uselect as select, uerrno as errno 3except ImportError: 4 try: 5 import socket, select, errno 6 7 select.poll # Raises AttributeError for CPython implementations without poll() 8 except (ImportError, AttributeError): 9 print("SKIP") 10 raise SystemExit 11 12 13poller = select.poll() 14 15s = socket.socket() 16 17poller.register(s) 18# https://docs.python.org/3/library/select.html#select.poll.register 19# "Registering a file descriptor that’s already registered is not an error, 20# and has the same effect as registering the descriptor exactly once." 21poller.register(s) 22 23# 2 args are mandatory unlike register() 24try: 25 poller.modify(s) 26except TypeError: 27 print("modify:TypeError") 28 29poller.modify(s, select.POLLIN) 30 31poller.unregister(s) 32 33try: 34 poller.modify(s, select.POLLIN) 35except OSError as e: 36 assert e.args[0] == errno.ENOENT 37 38# poll after closing the socket, should return POLLNVAL 39poller.register(s) 40s.close() 41p = poller.poll(0) 42print(len(p), p[0][-1]) 43