MCPcopy Create free account
hub / github.com/microsoft/debugpy / can_bind_ipv4_localhost

Function can_bind_ipv4_localhost

src/debugpy/common/sockets.py:12–22  ·  view source on GitHub ↗

Check if we can bind to IPv4 localhost.

()

Source from the content-addressed store, hash-verified

10from debugpy.common.util import hide_thread_from_debugger
11
12def can_bind_ipv4_localhost():
13 """Check if we can bind to IPv4 localhost."""
14 try:
15 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
16 sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
17 # Try to bind to IPv4 localhost on port 0 (any available port)
18 sock.bind(("127.0.0.1", 0))
19 sock.close()
20 return True
21 except (socket.error, OSError, AttributeError):
22 return False
23
24def can_bind_ipv6_localhost():
25 """Check if we can bind to IPv6 localhost."""

Callers 1

get_default_localhostFunction · 0.85

Calls 1

closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…