Skip to content

Commit fe538a1

Browse files
committed
added exit code term
1 parent 297b74d commit fe538a1

File tree

8 files changed

+33
-13
lines changed

8 files changed

+33
-13
lines changed

bibliography/bibliography.bib

+7
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,13 @@ @book{J2024PTOGBSI8IS12E
14131413
urldate = {2024-10-30},
14141414
}
14151415

1416+
@inbook{J2024PTOGBSI8IS12EETAP,
1417+
title = {\texttt{exit} -- Terminate a Process},
1418+
crossref = {J2024PTOGBSI8IS12E},
1419+
url = {https://pubs.opengroup.org/onlinepubs/9799919799/functions/exit.html},
1420+
urldate = {2024-10-30},
1421+
}
1422+
14161423
@inbook{J2024PTOGBSI8IS12ESSSSIS,
14171424
title = {\acrshort[hyper=true]{stderr}, \acrshort[hyper=true]{stdin}, \acrshort[hyper=true]{stdout} -- Standard {I/O} Streams},
14181425
crossref = {J2024PTOGBSI8IS12E},

notation/terms.sty

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ is another programming language, which is very successful in system programming
3333
}%
3434
%
3535
%
36+
\newglossaryentry{exitCode}{%
37+
name={exit code},%
38+
description={%
39+
When a process terminates, it can return a single integer value (the exit status code) to indicate success or failure~\cite{J2024PTOGBSI8IS12EETAP}. %
40+
Per convention, an exit code of~0 means success. %
41+
Any non-zero exit code indicates an error. %
42+
Under \python, you can terminate the current process at any time by calling \pythonilIdx{exit} and optionally passing in the exit code that should be returned. %
43+
If \pythonilIdx{exit} is not explicitly called, then the interpreter will return an exit code of~0 once the process normally terminates.%
44+
If the process was terminated by an uncaught \pythonilIdx{Exception}, a non-zero exit code, usually~1, is returned.%
45+
}%
46+
}%
47+
%
48+
%
3649
\newglossaryentry{exponent}{%
3750
name={exponent},%
3851
description={%

styles/listing.sty

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ $\downarrow$~~\expandafter\bashil{python3 #3}~~$\downarrow$%
275275
%
276276
$\downarrow$~~\expandafter\bashil{python3 #3}~~$\downarrow$%
277277
%
278-
\lstinputlisting[label={exec:#5},style=text_style,caption={The \gls{stdout} and \gls{stderr} as well as the exit code of the program~\href{\csname @pwp@gitUrl:lst:#5\endcsname}{\textil{#3}} given in~\cref{lst:#5}.}]{\csname @pwp@gitFile:exec:#5\endcsname}%
278+
\lstinputlisting[label={exec:#5},style=text_style,caption={The \gls{stdout} and \gls{stderr} as well as the \pgls{exitCode} of the program~\href{\csname @pwp@gitUrl:lst:#5\endcsname}{\textil{#3}} given in~\cref{lst:#5}.}]{\csname @pwp@gitFile:exec:#5\endcsname}%
279279
\end{figure}%
280280
}%
281281
%

text/back/scripts.tex

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
A unit test executed with \pytest\ will fail and exit with a non-zero exit code if the test, well, fails.
3030
A static code analysis tool like \ruff\ will fail with a non-zero exit code if it discovers any issue with the code.
3131
However, our scripts invoking these tools will \emph{not} fail in such cases.
32-
They will collect the exit code of the tool they are invoking and print it.
32+
They will collect the \pgls{exitCode} of the tool they are invoking and print it.
3333
Then they will exit with exit code~0.
3434
This is necessary for our book building process, which invokes these scripts to construct the outputs of the examples.
35-
If any of them would fail with non-zero exit code, the book building would fail as well.
35+
If any of them would fail with non-zero \pgls{exitCode}, the book building would fail as well.
3636
However, to illustrate that the tools are useful, we must apply them to cases where they would fail.
37-
So for our book, it is necessary that the scripts just print the exit codes while still returning successfully.
37+
So for our book, it is necessary that the scripts just print the \pglspl{exitCode} while still returning successfully.
3838
For a real productive environment, this is usually not what we want:
3939
We apply the tools to source code precisely to get them to fail on error, because if nothing fails, we know that everything seems to be OK.
4040
In such a practical environment, you would thus not want to use \emph{our} scripts, but you could use the same comments that we use.
@@ -46,7 +46,7 @@
4646
It then prints the command with a prepended~\expandafter\textil{\$}.
4747
Then, it executes it.
4848
\mypy\ will print its comments and messages to the standard output.
49-
Finally, the script shows the \mypy\ version and exit code in a brief success or failure message (with a prepended~\expandafter\textil{\#}).
49+
Finally, the script shows the \mypy\ version and \pgls{exitCode} in a brief success or failure message (with a prepended~\expandafter\textil{\#}).
5050
\Cref{exec:variables:variable_types_wrong_hints_1:mypy,exec:variables:variable_types_wrong_hints_2:mypy} are example outputs of this script.
5151

5252
\Cref{lst:bash:ruff} works basically the same way, just for \ruff.
@@ -71,7 +71,7 @@
7171
Either way, the script executes the test cases, prints the results as well as potential errors.
7272
Notice that we select some options to make the output less verbose, because for this book, we do want listings that are not too long.
7373
In practical scenarios, you may use different options.
74-
Either way, the script also prints the command that was executed at the beginning and the \pytest\ version used and the program's exit code at the end of the output.
74+
Either way, the script also prints the command that was executed at the beginning and the \pytest\ version used and the \pgls{exitCode} of the process at the end of the output.
7575
\Cref{exec:functions:test_my_math:pytest,exec:functions:test_my_math_2:pytest,exec:functions:test_my_math_3:pytest} are examples for the output of \pytest.%
7676
%
7777
\endhsection%

text/main/basics/gettingStarted/firstProgram/firstProgram.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
Indeed, the text \bashil{Hello World!} appears.
148148

149149
Well, before that text, we see the command line that was actually executed, namely the \python\ interpreter with our file's path as parameter.
150-
And after our program's output, we are notified that \inQuotes{Process finished with exit code~0,} which means that the program has completed successfully and without error.
150+
And after our program's output, we are notified that \inQuotes{Process finished with \pgls{exitCode}~0,} which means that the program has completed successfully and without error.
151151

152152
Congratulations.
153153
You now have written, saved, and executed your first ever \python\ program!%

text/main/basics/simpleDataTypesAndOperations/introduction/introduction.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
It must be a text.
1616

1717
The command \pythonil{exit}, on the other hand, can either have no parameter or one parameter.
18-
If it receives one parameter, this parameter will be the exit code of the program.
18+
If it receives one parameter, this parameter will be the \pgls{exitCode} of the program.
1919
Here, \pythonil{0} indicates success.
2020
If no parameter is provided, this will be used as default value.
2121
We need to invoke \pythonil{exit} if we use the \python\ console in the \pgls{terminal} explicitly.
22-
If we just run a program, then after the last instruction of the program was executed, then the interpreter will also terminate with exit code~0.
22+
If we just run a program, then after the last instruction of the program was executed, then the interpreter will also terminate with \pgls{exitCode}~0.
2323
Indeed, when we executed our first program in \cref{sec:ourFirstProgram}, we saw exactly that happen in \cref{fig:firstProgram09programResult}.
2424
Different from the parameter of \pythonil{print}, which must be some text, the parameter of \pythonil{exit} needs to be a number.
2525

text/main/basics/variables/typesAndTypeHints/typesAndTypeHints.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@
108108
All we have to do is invoke it in the terminal, giving the program to be checked as argument as well as some additional parameters.
109109
In \cref{exec:variables:variable_types_wrong:mypy}, we invoke \bashil{mypy variable_types_wrong.py --no-strict-optional --check-untyped-defs}, where \textil{variable_types_wrong.py} is the (very fitting) name of the program to check.
110110
Indeed, \mypy\ tells us that something dodgy is going on in the fourth line of that program, i.e., \pythonil{int_var = int_var / 3}.
111-
It will fail with an exit code of~\bashil{1}.
112-
Programs usually return~\bashil{0} as exit code if everything went well and some non-zero value if something went wrong.
111+
It will fail with an \pgls{exitCode} of~\bashil{1}.
112+
Programs usually return~\bashil{0} as \pgls{exitCode} if everything went well and some non-zero value if something went wrong.
113113
And something went wrong, because \mypy\ found the error.%
114114
%
115115
\usefulTool{mypy}{%

text/main/controlFlow/exceptions/exceptions.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
%
6969
\item The control flow immediately leaves the currently executed block of instructions as well as all calling blocks or functions.
7070
It jumps up in the call hierarchy until reaching code that handles the raised \pythonilIdx{Exception} is reached.
71-
If no such code exists, the current process is terminated with an exit code different from~\textil{0}.%
71+
If no such code exists, the current process is terminated with an \pgls{exitCode} different from~\textil{0}.%
7272
%
7373
\end{enumerate}%
7474
%
@@ -199,7 +199,7 @@
199199
In our original \pythonil{tuple} of inputs that we iteratively passed to \pythonil{sqrt}, the last three elements are \pythonilIdx{inf}, \pythonilIdx{nan}, and \pythonil{-1.0}.
200200
The call to \pythonil{sqrt} with \pythonil{inf} as argument was performed and failed.
201201
After that, no further output has been generated.
202-
Indeed, the control flow has left the \pythonil{for}~loop and the process has been terminated with exit code~1, as the output in \cref{exec:exceptions:use_sqrt_raise} shows.
202+
Indeed, the control flow has left the \pythonil{for}~loop and the process has been terminated with \pgls{exitCode}~1, as the output in \cref{exec:exceptions:use_sqrt_raise} shows.
203203

204204
Terminating the process may seem rash, but it is not.
205205
If a programmer used our \pythonil{sqrt} function incorrectly, then this will force them to fix their error.

0 commit comments

Comments
 (0)