MCPcopy Create free account
hub / github.com/dabeaz-course/python-mastery / run

Function run

Solutions/8_6/asyncserver.py:12–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10send_wait = {} # sock -> task
11
12def run():
13 while any([tasks, recv_wait, send_wait]):
14 while not tasks:
15 can_recv, can_send, _ = select(recv_wait, send_wait, [])
16 for s in can_recv:
17 tasks.append(recv_wait.pop(s))
18 for s in can_send:
19 tasks.append(send_wait.pop(s))
20 task = tasks.popleft()
21 try:
22 reason, resource = task.send(None)
23 if reason == 'recv':
24 recv_wait[resource] = task
25 elif reason == 'send':
26 send_wait[resource] = task
27 else:
28 raise RuntimeError('Unknown reason %r' % reason)
29 except StopIteration:
30 print('Task done')
31
32class GenSocket:
33 def __init__(self, sock):

Callers 1

asyncserver.pyFile · 0.70

Calls 2

appendMethod · 0.80
sendMethod · 0.45

Tested by

no test coverage detected