MCPcopy Index your code
hub / github.com/dabeaz-course/python-mastery / run

Function run

Solutions/8_5/server.py:11–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

server.pyFile · 0.70

Calls 2

appendMethod · 0.80
sendMethod · 0.45

Tested by

no test coverage detected