MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / select_poller

Function select_poller

src/network/asyncore_pollchoose.py:202–251  ·  view source on GitHub ↗

A poller which uses select(), available on most platforms.

(timeout=0.0, map=None)

Source from the content-addressed store, hash-verified

200 obj.handle_error()
201
202def select_poller(timeout=0.0, map=None):
203 """A poller which uses select(), available on most platforms."""
204 if map is None:
205 map = socket_map
206 if map:
207 r = []; w = []; e = []
208 for fd, obj in list(map.items()):
209 is_r = obj.readable()
210 is_w = obj.writable()
211 if is_r:
212 r.append(fd)
213 # accepting sockets should not be writable
214 if is_w and not obj.accepting:
215 w.append(fd)
216 if is_r or is_w:
217 e.append(fd)
218 if [] == r == w == e:
219 time.sleep(timeout)
220 return
221
222 try:
223 r, w, e = select.select(r, w, e, timeout)
224 except KeyboardInterrupt:
225 return
226 except socket.error as err:
227 if err.args[0] in (EBADF, EINTR):
228 return
229 except Exception as err:
230 if err.args[0] in (WSAENOTSOCK, ):
231 return
232
233 for fd in random.sample(r, len(r)):
234 obj = map.get(fd)
235 if obj is None:
236 continue
237 read(obj)
238
239 for fd in random.sample(w, len(w)):
240 obj = map.get(fd)
241 if obj is None:
242 continue
243 write(obj)
244
245 for fd in e:
246 obj = map.get(fd)
247 if obj is None:
248 continue
249 _exception(obj)
250 else:
251 current_thread().stop.wait(timeout)
252
253def poll_poller(timeout=0.0, map=None):
254 """A poller which uses poll(), available on most UNIXen."""

Callers

nothing calls this directly

Calls 8

readFunction · 0.85
writeFunction · 0.85
_exceptionFunction · 0.85
itemsMethod · 0.80
waitMethod · 0.80
readableMethod · 0.45
writableMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected