Instant Download (Ebook) Python Debugging for AI, Machine Learning, and Cloud Computing by Dmitry Vostokov ISBN 9781484297452, 1484297458 PDF All Chapters
Instant Download (Ebook) Python Debugging for AI, Machine Learning, and Cloud Computing by Dmitry Vostokov ISBN 9781484297452, 1484297458 PDF All Chapters
com
https://ebooknice.com/product/python-debugging-for-ai-
machine-learning-and-cloud-computing-55714196
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018
ebooknice.com
ebooknice.com
(Ebook) Cambridge IGCSE and O Level History Workbook 2C -
Depth Study: the United States, 1919-41 2nd Edition by
Benjamin Harrison ISBN 9781398375147, 9781398375048,
1398375144, 1398375047
https://ebooknice.com/product/cambridge-igcse-and-o-level-history-
workbook-2c-depth-study-the-united-states-1919-41-2nd-edition-53538044
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
Dmitry Vostokov
Apress Standard
The publisher, the authors, and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
1. Fundamental Vocabulary
Dmitry Vostokov1
Process
A Python script is interpreted by compiling it into bytecode and then executing it, or it
can even be precompiled into an application program. In both cases, this interpreter file
or the compiled application is an executable program (in Windows, it may have a .exe
extension) that references some operating system libraries (.dll in Windows and .so in
Linux). This application can be loaded into computer memory several times; each time, a
separate process is created with its own resources and unique process ID (PID, also
TGID), as shown in Figure 1-1. The process may also have a parent process that created it,
with a parent process ID (PPID).
Figure 1-1 Two python3 processes with two different PIDs
To illustrate, I executed the code in Listing 1-1 on both Windows and Linux twice.
import time
def main():
foo()
def foo():
bar()
def bar():
while True:
time.sleep(1)
if __name__ == "__main__":
main()
Listing 1-1 A Simple Script to Model Running Python Code
~/Chapter1$ ps -a
PID TTY TIME CMD
17 pts/0 00:00:00 mc
60 pts/2 00:00:00 python3
61 pts/1 00:00:00 python3
80 pts/3 00:00:00 ps
Note The operating system controls hardware and processes/threads. From a high
level, it is just a collection of processes with the operating system kernel as a process
too.
Thread
From an operating system perspective, a process is just a memory container for a Python
interpreter, its code, and data. But the interpreter code needs to be executed, for example,
to interpret the Python bytecode. This unit of execution is called a thread. A process may
have several such units of execution (several threads, the so-called multithreaded
application). Each thread has its own unique thread ID (TID, also LWP or SPID), as shown
in Figure 1-3. For example, one thread may process user interface events and others may
do complex calculations in response to UI requests, thus making the UI responsive. On
Windows, thread IDs are usually different from process IDs, but in Linux, the thread ID of
the main thread is the same as the process ID for a single-threaded process.
import time
import threading
def thread_func():
foo()
def main():
t1 = threading.Thread(target=thread_func)
t1.start()
t2 = threading.Thread(target=thread_func)
t2.start()
t1.join()
t2.join()
def foo():
bar()
def bar():
while True:
time.sleep(1)
if __name__ == "__main__":
main()
Listing 1-2 A Simple Script to Model Multiple Threads
Figure 1-4 shows that in Windows, you can see 11 threads at the beginning (this
number later changes to 7 and then to 5). You see that the number of threads may be
greater than expected.
Figure 1-4 The number of threads in the running python3.11.exe process on Windows
~/Chapter1$ ps -aT
PID SPID TTY TIME CMD
17 17 pts/0 00:00:00 mc
45 45 pts/2 00:00:00 python3
45 46 pts/2 00:00:00 python3
45 47 pts/2 00:00:00 python3
54 54 pts/1 00:00:00 ps
Stack Trace (Backtrace, Traceback)
I should distinguish Python source code tracebacks (which we call managed stack traces)
and unmanaged (native) ones from the Python compiler and interpreter that compiles to
and executes Python byte code. You will see this distinction in some chapters for several
case studies and how to get both traces. But, for now, I will just show the difference.
Listing 1-3 shows managed stack trace. Listing 1-4 shows the corresponding unmanaged
Linux stack trace with debugging symbols (the most recent call first). Listing 1-5 shows
the corresponding unmanaged Windows stack trace without debugging symbols (the
most recent call first).
00 00000090`7e1ef0a8
00007ff9`8c44fcf9 ntdll!NtWaitForMultipleObjects+0x14
01 00000090`7e1ef0b0
00007ff9`8c44fbfe KERNELBASE!WaitForMultipleObjectsEx+0xe9
02 00000090`7e1ef390
00007ff8`ef943986 KERNELBASE!WaitForMultipleObjects+0xe
03 00000090`7e1ef3d0
00007ff8`ef94383d python311!PyTraceBack_Print_Indented+0x35a
04 00000090`7e1ef430
00007ff8`ef81a6b2 python311!PyTraceBack_Print_Indented+0x211
Random documents with unrelated
content Scribd suggests to you:
Pikku Anna oli tosin tottunut jäämään yksiksensä kotiin, mutta
kuitenkin oli hänellä ikävä aina yksin jäädessänsä. Kaikkein ikävintä
oli se, kun hän aina tunsi voimansa vähäisiksi, jos mihin vähänkin
suurempaa ponnistusta vaadittiin. Hän ihmetteli usein, miksi hän
aina oli väsynyt, sairas ja kykenemätön kaikkeen työhön, kun
sitävastoin toiset lapset, kuten Matleena-muorin pojat, olivat aina
terveitä ja voivat myllätä ja vääntää kuin karhut. Tätä kysymystä hän
mietti joka päivä ja kaikesta sydämestään halusi saada siihen
vastausta. Oi, miten hän toivoi kerran joltain ihmiseltä saavansa
kysellä kaikkea, mitä hän yksiksensä oli mietiskellyt, ja jota hän ei
itse ymmärtänyt selittää! Koulunopettaja tai pappi varmaan osaisi
selittää, mutta koska hän voisi heitä tavata? Kouluun pääsemistä ei
hän voinut ajatella, sillä koulu oli liian kaukana, ja vanhaa rovastia
hän voisi vielä vähemmin tavata.
Ilta alkoi lähestyä, ja kun Anna muisti, että oli vähän puuroa, joka
hänen tuli lämmittää itselleen illalliseksi, meni hän sitä varten
keräämään risuja mäeltä. Hänen piti näet itse hoitaa itsensä, sillä
marjamiehet tulisivat kotiin vasta seuraavan päivän aamupuolella.
*****
*****
Hänen ainoa huolensa oli siitä kuinka hän osaisi kyllin kiittää tästä
onnellisesta hetkestä.
Hupsu-Elias.
Oli lämmin kesäinen ilta. Kylän pojat loikoilivat tapansa mukaan
Vasikkahaan katajikossa. Mutta ikävältä alkoi sekin ammatti
ajanpitkään tuntua, vaikka Pitkä-Roopertti ja Nikkarin Saska koettivat
tuontuostakin saada naurua aikaan jos jonkinlaisilla kujeilla.
*****
Laurin joulu-unelma.
Pikku Lauri oli ollut ensi kertaa jouluna kirkossa. Voi kuinka
hauskaa siellä oli juhlapukuisen kansan keskellä vieressä oman isän
ja äidin! Lukemattomat joulukynttilät loivat kirkasta valoaan yli
korkeakattoisen temppelin, ja kruunut kimaltelivat kirkkaina niiden
loisteessa. Kaikki ihastutti Lauria niin, että hän mielellään olisi
taputtanut pieniä kätösiään, elleivät kaikki ihmiset olisi näyttäneet
niin vakavilta. Äiti kehotti kuuntelemaan papin kaunista puhetta
Jesuslapsesta, joka syntyi kunnian kuninkaaksi Betlehemin seimessä.
Mutta vielä juhlallisempaa oli Laurin mielestä urkujen soitto ja
seurakunnan täysiääninen veisuu, jota hän lapsenäänellään koetti
hiljaa säestää.
"Ei äitisi sitä tiedä, poikaseni, eikä ole nähnyt, mutta sen äitisi
tietää, että metsän puutkin pitävät omalla tavallaan
jumalanpalvelusta siinä suuressa ja ihanassa temppelissä, jonka
Jumalan kädet ovat perustaneet. Kun sinä tulet suureksi, niin opit
sen vielä näkemään ja ymmärtämään", vastasi äiti.
Martin koulumatka.
"No, näytähän nyt, Martti, että olet mies ja miehen poika. Akka
olet, ellet laske, kun kerran kerskasit!"
*****
Äiti kertoi silloin, että Martti oli kaksi päivää sitten kannettu kotiin.
Hän oli taittanut jalkansa, laskiessaan Kurjenmäestä. Isä oli heti
haettanut lääkärin, joka sitoi säären ja asetti luut paikoillensa.
Opettajakin oli jo kahdesti käynyt häntä katsomassa ja luvannut
antaa kaikki anteeksi, kun Martti vain pian paraneisi. Kalle ja Antti
olivat heti samana päivänä menneet opettajan luo ja kertoneet itse
kiihottaneensa Marttia tähän uhkarohkeaan tekoon, joka oli vähällä
maksaa hänelle hengen. Poikain hartaista pyynnöistä oli hyvä
opettaja luvannut ottaa heidätkin takaisin kouluun, kun lupasivat olla
oikein nöyriä ja ahkeria.
Laiskan-Matin velka.
— Mutta nyt lupaan oikein todesti, niin totta kuin nimeni on Matti!
— Hyvä Haltia, rakas Haltia, enkö voisi saada jo tänä jouluna, jos
oikein varmasti parannan itseni?
Haltia naurahti.
— Matti myös.
— Oikein on! vastasi Matti. Hih vaan! Eipä niitä paljo ollutkaan!
— Ei, sanoi Haltia. — Ensimäinen täplä: yksi kertaa — toinen
täplä: kaksi kertaa — kolmas täplä: neljä kertaa — neljäs täplä:
kahdeksan kertaa — viides täplä: 16 kertaa — kuudes: 32 kertaa —
seitsemäs: 64 kertaa — kahdeksas: 128 kertaa — yhdeksäs: 256
kertaa — kymmenes: 512 kertaa.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com