Skip to content

Commit 00ef823

Browse files
Handle module
1 parent b3b6fff commit 00ef823

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Lib/profiling/sampling/cli.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,14 @@ def _handle_attach(args):
614614

615615
def _handle_run(args):
616616
"""Handle the 'run' command."""
617-
# Validate script exists (only for scripts, not modules)
618-
if not args.module and not os.path.exists(args.target):
619-
sys.exit(f"Error: script not found: {args.target}")
617+
# Validate target exists before launching
618+
if args.module:
619+
import importlib.util
620+
if importlib.util.find_spec(args.target) is None:
621+
sys.exit(f"Error: module not found: {args.target}")
622+
else:
623+
if not os.path.exists(args.target):
624+
sys.exit(f"Error: script not found: {args.target}")
620625

621626
# Check if live mode is requested
622627
if args.live:

0 commit comments

Comments
 (0)