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

Function has_remote_subprocess_debugging

Lib/test/support/__init__.py:662–730  ·  view source on GitHub ↗

Check if we have permissions to debug subprocesses remotely. Returns True if we have permissions, False if we don't. Checks for: - Platform support (Linux, macOS, Windows only) - On Linux: process_vm_readv support - _remote_debugging module availability - Actual subprocess d

()

Source from the content-addressed store, hash-verified

660
661@functools.cache
662def has_remote_subprocess_debugging():
663 """Check if we have permissions to debug subprocesses remotely.
664
665 Returns True if we have permissions, False if we don't.
666 Checks for:
667 - Platform support (Linux, macOS, Windows only)
668 - On Linux: process_vm_readv support
669 - _remote_debugging module availability
670 - Actual subprocess debugging permissions (e.g., macOS entitlements)
671 Result is cached.
672 """
673 # Check platform support
674 if sys.platform not in ("linux", "darwin", "win32"):
675 return False
676
677 try:
678 import _remote_debugging
679 except ImportError:
680 return False
681
682 # On Linux, check for process_vm_readv support
683 if sys.platform == "linux":
684 if not getattr(_remote_debugging, "PROCESS_VM_READV_SUPPORTED", False):
685 return False
686
687 # First check if we can read our own process
688 if not _remote_debugging.is_python_process(os.getpid()):
689 return False
690
691 # Check subprocess access - debugging child processes may require
692 # additional permissions depending on platform security settings
693 import socket
694 import subprocess
695
696 # Create a socket for child to signal readiness
697 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
698 server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
699 server.bind(("127.0.0.1", 0))
700 server.listen(1)
701 port = server.getsockname()[1]
702
703 # Child connects to signal it's ready, then waits for parent to close
704 child_code = f"""
705import socket
706s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
707s.connect(("127.0.0.1", {port}))
708s.recv(1) # Wait for parent to signal done
709"""
710 proc = subprocess.Popen(
711 [sys.executable, "-c", child_code],
712 stdout=subprocess.DEVNULL,
713 stderr=subprocess.DEVNULL,
714 )
715 try:
716 server.settimeout(5.0)
717 conn, _ = server.accept()
718 # Child is ready, test if we can probe it
719 result = _remote_debugging.is_python_process(proc.pid)

Callers 1

Calls 11

pollMethod · 0.95
killMethod · 0.95
waitMethod · 0.95
socketMethod · 0.80
setsockoptMethod · 0.45
bindMethod · 0.45
listenMethod · 0.45
getsocknameMethod · 0.45
settimeoutMethod · 0.45
acceptMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…