On this page
sys.exit
Prev: sys.exception | Up: sys | Next: sys.get_asyncgen_hooks
Rel: sys.activate_stack_trampoline, sys.addaudithook, sys.audit, sys.breakpointhook
Ref: docs.python.org — sys.exit
Tags: #public #python3 #stdlib #sys
Import
import sys
from sys import exit
Signature & Overview
sys.exit(status=None, /)
Exit the interpreter by raising SystemExit(status).
Usage
import sys
try:
sys.exit(2)
except SystemExit as exc:
assert exc.code == 2
Gotchas
- Raises
SystemExit(aBaseException): Runsfinally:blocks andatexithandlers cleanly; passing a non-emptystrprints it tostderrand exits with code1.
REPL Inspect
from sys import exit
help(exit)
Linked from
Related notes
- tuts/python3/stdlib_module/sys/exception Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/get_asyncgen_hooks Linked here; links to this page; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/sys/activate_stack_trampoline Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/addaudithook Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/audit Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/breakpointhook Linked here; shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/call_tracing shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/deactivate_stack_trampoline shared tags: #stdlib, #sys
- tuts/python3/stdlib_module/sys/displayhook shared tags: #stdlib, #sys