Skip to content

Commit 733495c

Browse files
committed
Refactored kernprof exception managerent
kernprof.py::_main_profile() - Unnested the `try` block - Removed explicit suppression of `KeyboardInterrupt` and `SystemExit`
1 parent fcb80fd commit 733495c

1 file changed

Lines changed: 27 additions & 30 deletions

File tree

kernprof.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,36 +1064,33 @@ def _main_profile(options, module=False):
10641064
"""
10651065
script_file, prof = _pre_profile(options, module)
10661066
try:
1067-
try:
1068-
rmod = functools.partial(run_module,
1069-
run_name='__main__', alter_sys=True)
1070-
ns = {'__file__': script_file, '__name__': '__main__',
1071-
'execfile': execfile, 'rmod': rmod,
1072-
'prof': prof}
1073-
if options.prof_mod and options.line_by_line:
1074-
from line_profiler.autoprofile import autoprofile
1075-
_call_with_diagnostics(
1076-
options,
1077-
autoprofile.run, script_file, ns,
1078-
prof_mod=options.prof_mod,
1079-
profile_imports=options.prof_imports,
1080-
as_module=module is not None)
1081-
elif module and options.builtin:
1082-
_call_with_diagnostics(options, rmod, options.script, ns)
1083-
elif options.builtin:
1084-
_call_with_diagnostics(options, execfile, script_file, ns, ns)
1085-
elif module:
1086-
_call_with_diagnostics(
1087-
options,
1088-
prof.runctx, f'rmod({options.script!r}, globals())',
1089-
ns, ns)
1090-
else:
1091-
_call_with_diagnostics(
1092-
options,
1093-
prof.runctx, f'execfile({script_file!r}, globals())',
1094-
ns, ns)
1095-
except (KeyboardInterrupt, SystemExit):
1096-
pass
1067+
rmod = functools.partial(run_module,
1068+
run_name='__main__', alter_sys=True)
1069+
ns = {'__file__': script_file, '__name__': '__main__',
1070+
'execfile': execfile, 'rmod': rmod,
1071+
'prof': prof}
1072+
if options.prof_mod and options.line_by_line:
1073+
from line_profiler.autoprofile import autoprofile
1074+
_call_with_diagnostics(
1075+
options,
1076+
autoprofile.run, script_file, ns,
1077+
prof_mod=options.prof_mod,
1078+
profile_imports=options.prof_imports,
1079+
as_module=module is not None)
1080+
elif module and options.builtin:
1081+
_call_with_diagnostics(options, rmod, options.script, ns)
1082+
elif options.builtin:
1083+
_call_with_diagnostics(options, execfile, script_file, ns, ns)
1084+
elif module:
1085+
_call_with_diagnostics(
1086+
options,
1087+
prof.runctx, f'rmod({options.script!r}, globals())',
1088+
ns, ns)
1089+
else:
1090+
_call_with_diagnostics(
1091+
options,
1092+
prof.runctx, f'execfile({script_file!r}, globals())',
1093+
ns, ns)
10971094
finally:
10981095
_post_profile(options, prof)
10991096

0 commit comments

Comments
 (0)