From 50e58c6377013ad00eca27ff71f97bdd9dacd6f0 Mon Sep 17 00:00:00 2001 From: srosales4 <35977237+srosales4@users.noreply.github.com> Date: Sun, 9 Sep 2018 23:27:15 -0600 Subject: [PATCH] Add notes from Aug. 30's lecture --- ch2/threads_v0.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ch2/threads_v0.py b/ch2/threads_v0.py index 7afd94e..6bdeaf7 100644 --- a/ch2/threads_v0.py +++ b/ch2/threads_v0.py @@ -7,6 +7,7 @@ global count count = 0 +# This argument is used to tell the thread how many iters to go, e.g. 1000 itersPerThread = int(argv[1]) threadNum = 0 @@ -17,6 +18,9 @@ def __init__(self, iters): Thread.__init__(self, name="Thread-%d" % threadNum); threadNum += 1 self.iters = iters + # Calling run creates a new virtual machine + # That virtual machine doesn't start running until I tell the thread to start + # Once it stops the virtual machine is destroyed def run(self): global count for i in range(self.iters): @@ -29,6 +33,8 @@ def delay(sec): workers = [Worker(itersPerThread).start(), Worker(itersPerThread).start()] +# Enumerate is a method of the Thread class. It returns a list of threads that are +# still running while len(enumerate()) > 1: delay(0.25) print("activeThreads=%s, count=%d" % (enumerate(), count))