1# test select.poll on UDP sockets 2 3try: 4 import usocket as socket, uselect as select 5except ImportError: 6 try: 7 import socket, select 8 except ImportError: 9 print("SKIP") 10 raise SystemExit 11 12 13s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 14s.bind(socket.getaddrinfo("127.0.0.1", 8000)[0][-1]) 15poll = select.poll() 16 17# UDP socket should not be readable 18poll.register(s, select.POLLIN) 19print(len(poll.poll(0))) 20 21# UDP socket should be writable 22poll.modify(s, select.POLLOUT) 23print(poll.poll(0)[0][1] == select.POLLOUT) 24 25# same test for select.select, but just skip it if the function isn't available 26if hasattr(select, "select"): 27 r, w, e = select.select([s], [], [], 0) 28 assert not r and not w and not e 29