MCPcopy
hub / github.com/dmlc/dgl / get_local_usable_addr

Function get_local_usable_addr

tests/python/pytorch/distributed/optim/test_dist_optim.py:40–63  ·  view source on GitHub ↗

Get local usable IP and port Returns ------- str IP address, e.g., '192.168.8.12:50051'

()

Source from the content-addressed store, hash-verified

38
39
40def get_local_usable_addr():
41 """Get local usable IP and port
42
43 Returns
44 -------
45 str
46 IP address, e.g., '192.168.8.12:50051'
47 """
48 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
49 try:
50 # doesn't even have to be reachable
51 sock.connect(("10.255.255.255", 1))
52 ip_addr = sock.getsockname()[0]
53 except ValueError:
54 ip_addr = "127.0.0.1"
55 finally:
56 sock.close()
57 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
58 sock.bind(("", 0))
59 sock.listen(1)
60 port = sock.getsockname()[1]
61 sock.close()
62
63 return ip_addr + " " + str(port)
64
65
66def prepare_dist():

Callers 1

prepare_distFunction · 0.70

Calls 1

closeMethod · 0.45

Tested by

no test coverage detected