Python base python os._exit () Sys.exit () exit () Difference

Source: Internet
Author: User
Tags exit in

There are two ways that Python exits a program: Os._exit (), Sys.exit ()

1) os._exit () exits the Python program directly, and the subsequent code will not continue to execute.

2) Sys.exit () throws a systemexit exception, and if the exception is not caught, the Python interpreter exits directly, and catching this exception can do some extra cleanup work. 0 for normal exit, other values (1-127) are not normal, can throw abnormal events for capture.

Exit () should be the same as exit () in other languages such as C language.

Os._exit () invokes the C-language _exit () function.
__builtin__.exit is a quitter object, and the __call__ method of the object throws a Systemexit exception.

Generally os._exit () is used to exit in the thread
Sys.exit () is used to exit from the main thread.

Python base python os._exit () Sys.exit () exit () Difference

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.