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
()
| 660 | |
| 661 | @functools.cache |
| 662 | def 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""" |
| 705 | import socket |
| 706 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 707 | s.connect(("127.0.0.1", {port})) |
| 708 | s.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) |
no test coverage detected
searching dependent graphs…