MCPcopy Index your code
hub / github.com/python/cpython / run_udp_echo_server

Function run_udp_echo_server

Lib/test/test_asyncio/utils.py:282–298  ·  view source on GitHub ↗
(*, host='127.0.0.1', port=0)

Source from the content-addressed store, hash-verified

280
281@contextlib.contextmanager
282def run_udp_echo_server(*, host='127.0.0.1', port=0):
283 addr_info = socket.getaddrinfo(host, port, type=socket.SOCK_DGRAM)
284 family, type, proto, _, sockaddr = addr_info[0]
285 sock = socket.socket(family, type, proto)
286 sock.bind((host, port))
287 sockname = sock.getsockname()
288 thread = threading.Thread(target=lambda: echo_datagrams(sock))
289 thread.start()
290 try:
291 yield sockname
292 finally:
293 # gh-122187: use a separate socket to send the stop message to avoid
294 # TSan reported race on the same socket.
295 sock2 = socket.socket(family, type, proto)
296 sock2.sendto(b'STOP', sockname)
297 sock2.close()
298 thread.join()
299
300
301def make_test_protocol(base):

Callers

nothing calls this directly

Calls 9

startMethod · 0.95
joinMethod · 0.95
echo_datagramsFunction · 0.85
socketMethod · 0.80
getaddrinfoMethod · 0.45
bindMethod · 0.45
getsocknameMethod · 0.45
sendtoMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…