break
Just comes out of a loop and does not finish the application, it is less than a return
. Up to a return
can close the application when it is in the same function as the input point.
sys.exit()
( Module sys
);
Closes the application by launching an exception (SystemExit
) which can be handled at some point, and any closure process, including release of appeals, is executed before it ends. It is considered that its use is not ideal and should only be called in very specific cases where you understand well what you are doing and need exactly this immediate termination solution. Particularly I don’t think so bad if it really has nothing else to accomplish, at least on well-made architectures that have no dependency on a specific closure. Use it preferably.
os._exit()
(Module os
);
Terminates the execution immediately without giving chance to perform anything else, not even the release of resources.
exit()
The same as the sys.exit()
, but it is considered that it should not be used. I am not sure why, but I believe that functions that do not belong to modules become ambiguous. Use in many simple codes or in REPL when importing a module can be worse. That’s the problem of the language that starts to be script and then it changes to be more than that.
quit()
Just a nickname for the previous function. Clear violation of "only having a way to accomplish something".
There is nothing kernel there, only that the os.exit()
is a closing call that probably asks the OS to end without further ceremony. There is no link to any routine. That seems like a misunderstanding. It’s a function like any other that you call at some point in the code and it executes something, in which case this something is the closure of the application.
Obs.: the functions
exit()
andquit()
are defined in the modulesite
, which is automatically imported into context by the interpreter, unless the flag is used-S
when executing the code. With the flag, the functions will not be defined, so it is not very indicated to depend on them.– Woss
great answer, thank you! In my case for example, the ideal then is to use (sys.Exit()), because I intend to use in situations where it is not necessary to execute anything later. Really many options end up confusing rs
– Clayton Tosatti