sys.exit(1) vs raise SystemExit vs raise
Ganesh Pal
ganesh1pal at gmail.com
Tue Apr 12 10:12:39 EDT 2016
>
>
> No; raise SystemExit is equivalent to sys.exit(0); you would need raise
> SystemExit(1) to return 1.
>
Thanks will replace SystemExit with SystemExit(1) .
> Why do you want to do this, though? What do you think you gain from it?
>
Iam trying to have a single exit point for many functions: example
create_logdir() , create_dataset() and unittest.main() will bubble out an
exception using raise
I would want to terminate the program when this happens .
Do you see any problem if *raise *SystemExit(1) is used in the except block ?
*def *main():
*try*:
create_logdir()
create_dataset()
unittest.main()
*except *Exception *as *e:
logging.exception(e)
*raise *SystemExit(1)
I see the below error only on pdb so thinking whats wrong in the above code
?
“*Exception AttributeError: "'NoneType' object has no attribute 'path'" in
<function _remove at 0x8017466e0> ignored “ *
(Pdb) n
SystemExit: SystemExit()
> /var/crash/local_qa/bin/corrupt_test.py(253)<module>()
-> main()
(Pdb) n
--Return--
> /var/crash/local_qa/bin/corrupt_test.py(253)<module>()->None
-> main()
(Pdb) n
Exception AttributeError: "'NoneType' object has no attribute 'path'" in
<function _remove at 0x8017466e0> ignored
More information about the Python-list
mailing list