overview strong> h3>
The
Python program has two exits: os._exit() and sys.exit(). I looked up the difference between the two approaches.
os._exit() terminates the python program directly, and none of the code after that executes.
sys.exit() throws an exception: SystemExit, and if the exception is not caught, the python interpreter exits. If there is code to catch the exception, it will still execute.
for example
import os
try:
os._exit(0)
except:
print('Program is dead.')
this print does not print because no exception is caught.
import sys
try:
sys.exit(0)
except:
print('Program is dead.')
finally:
print('clean-up')
Both print here because sys.exit() throws an exception.
Conclusion
strong> h3>
exits the program gracefully by using sys.exit(), which raises a SystemExit exception, which we can then catch and do some cleanup. Os._exit () simply exits the Python interpreter, and none of the following statements are executed.
, in general, use sys.exit(); Os._exit () can be used in the child process produced by os.fork().
reference:
p> [1] https://docs.python.org/3.5/library/exceptions.html
p> [2] http://www.cnblogs.com/gaott/archive/2013/04/12/3016355.html
import os
try:
os._exit(0)
except:
print('Program is dead.')
import sys
try:
sys.exit(0)
except:
print('Program is dead.')
finally:
print('clean-up')
exits the program gracefully by using sys.exit(), which raises a SystemExit exception, which we can then catch and do some cleanup. Os._exit () simply exits the Python interpreter, and none of the following statements are executed.
, in general, use sys.exit(); Os._exit () can be used in the child process produced by os.fork().
reference:
p> [1] https://docs.python.org/3.5/library/exceptions.html
p> [2] http://www.cnblogs.com/gaott/archive/2013/04/12/3016355.html
Read More:
- Git did not exit cleanly (exit code 128)
- Error: Command ‘/ usr / bin / clang’ failed with exit status 1 solution for Mac OS installation
- [solution] visual studio will exit automatically after debugging the program
- How does a Mac terminal exit the python command line
- Install Python package under MacOS: “error: Command ‘GCC’ failed with exit status 1”
- Python installation problem: error: Command erred out with exit status 1:
- Python program uses OS. System () method to call exe program, resulting in no response of main program process
- Python error: command error out with exit status 1:
- Error creating Django application: error on Python side.Exit code:1.
- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full comm
- Python MAC installation mysqlclient package error “error: Command ‘clang’ failed with exit status 1” solution
- Python Mac installs mysqlclient package error “error: command’clang’ failed with exit status 1” solution
- Error: command error out with exit status 1: Python setup.py egg_ inf
- Command errored out with exit status 1: python setup.py egg_info Check the logs for full command ou
- sys.path.append(), os.path.exists(), os.path.join() and os.makedirs() meaning
- Error: command error out with exit status 1: Python setup.py egg_ info Check the ”
- Error: command error out with exit status 1: Python when installing mysqlclient in centos7 setup.py egg_ info Check
- Error: command error out with exit status 1: Python when installing mysqlclient in django2.0 setup.py egg_ info
- Building wheel for vrep-api-python (setup.py) … error ERROR: Command errored out with exit statu
- Why can’t Scala shell enter Q to exit