Check if we can bind to IPv4 localhost.
()
| 10 | from debugpy.common.util import hide_thread_from_debugger |
| 11 | |
| 12 | def 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 | |
| 24 | def can_bind_ipv6_localhost(): |
| 25 | """Check if we can bind to IPv6 localhost.""" |
no test coverage detected
searching dependent graphs…