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

Function _validate_args

Lib/profiling/sampling/cli.py:697–806  ·  view source on GitHub ↗

Validate format-specific options and live mode requirements. Args: args: Parsed command-line arguments parser: ArgumentParser instance for error reporting

(args, parser)

Source from the content-addressed store, hash-verified

695
696
697def _validate_args(args, parser):
698 """Validate format-specific options and live mode requirements.
699
700 Args:
701 args: Parsed command-line arguments
702 parser: ArgumentParser instance for error reporting
703 """
704 # Replay command has no special validation needed
705 if getattr(args, 'command', None) == "replay":
706 return
707
708 # Warn about blocking mode with aggressive sampling intervals
709 if args.blocking and args.sample_interval_usec < 100:
710 print(
711 f"Warning: --blocking with a {args.sample_interval_usec} µs interval will stop all threads "
712 f"{1_000_000 // args.sample_interval_usec} times per second. "
713 "Consider using --sampling-rate 1khz or lower to reduce overhead.",
714 file=sys.stderr
715 )
716
717 # Check if live mode is available
718 if hasattr(args, 'live') and args.live and LiveStatsCollector is None:
719 parser.error(
720 "Live mode requires the curses module, which is not available."
721 )
722
723 # --subprocesses is incompatible with --live
724 if hasattr(args, 'subprocesses') and args.subprocesses:
725 if ChildProcessMonitor is None:
726 parser.error(
727 "--subprocesses is not available on this platform "
728 "(requires _remote_debugging module)."
729 )
730 if hasattr(args, 'live') and args.live:
731 parser.error("--subprocesses is incompatible with --live mode.")
732
733 # Async-aware mode is incompatible with --native, --no-gc, --mode, and --all-threads
734 if getattr(args, 'async_aware', False):
735 issues = []
736 if args.native:
737 issues.append("--native")
738 if not args.gc:
739 issues.append("--no-gc")
740 if hasattr(args, 'mode') and args.mode != "wall":
741 issues.append(f"--mode={args.mode}")
742 if hasattr(args, 'all_threads') and args.all_threads:
743 issues.append("--all-threads")
744 if issues:
745 parser.error(
746 f"Options {', '.join(issues)} are incompatible with --async-aware. "
747 "Async-aware profiling uses task-based stack reconstruction."
748 )
749
750 # --async-mode requires --async-aware
751 if hasattr(args, 'async_mode') and args.async_mode != "running" and not getattr(args, 'async_aware', False):
752 parser.error("--async-mode requires --async-aware to be enabled.")
753
754 # Live mode is incompatible with format options

Callers 2

_mainFunction · 0.85

Calls 3

errorMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…