MCPcopy Create free account
hub / github.com/dabeaz/python-cookbook / echo_server

Function echo_server

src/12/how_to_create_a_thread_pool/example2.py:19–34  ·  view source on GitHub ↗
(addr, nworkers)

Source from the content-addressed store, hash-verified

17 sock.close()
18
19def echo_server(addr, nworkers):
20 print('Echo server running at', addr)
21 # Launch the client workers
22 q = Queue()
23 for n in range(nworkers):
24 t = Thread(target=echo_client, args=(q,))
25 t.daemon = True
26 t.start()
27
28 # Run the server
29 sock = socket(AF_INET, SOCK_STREAM)
30 sock.bind(addr)
31 sock.listen(5)
32 while True:
33 client_sock, client_addr = sock.accept()
34 q.put((client_sock, client_addr))
35
36echo_server(('',15000), 128)

Callers 1

example2.pyFile · 0.70

Calls 3

acceptMethod · 0.80
startMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected