February 2019
Intermediate to advanced
672 pages
16h 50m
English
Let's consider a specific example. In this example, we will be looking at the Chapter10/example4.py file. We will go back to the thread example of counting down from five to one, which we looked at at the beginning of this chapter; take a moment to look back if you do not remember the problem. In this example, we will be tweaking the MyThread class, as follows:
# Chapter10/example4.pyimport threadingimport timeclass MyThread(threading.Thread): def __init__(self, name, delay): threading.Thread.__init__(self) self.name = name self.delay = delay def run(self): print('Starting thread %s.' % self.name) thread_lock.acquire() thread_count_down(self.name, self.delay) thread_lock.release() print('Finished thread %s.' % self.name) ...