亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

python在寫多線程有個疑問
PHPz
PHPz 2017-04-17 17:27:11
0
2
374

from threading import Thread

class CountdownThread(Thread):
    def __init__(self, n):
        super(CountdownThread, self).__init__()   #在繼承Thread時,為什么要執(zhí)行Thread的構(gòu)造函數(shù)呢?
        self.n = 0
    def run(self):
        while self.n > 0:
            print('T-minus', self.n)
            self.n -= 1
            time.sleep(5)
c = CountdownThread(5)
c.start()

1.在繼承Thread時,為什么要執(zhí)行Tread的構(gòu)造函數(shù)呢?

ps:本人背景自學(xué)+google,還請不吝賜教

PHPz
PHPz

學(xué)習(xí)是最好的投資!

reply all(2)
Ty80

The constructor of the parent class has thread initialization work.

For example: when a disciple inherits a teacher’s profession, he can’t just innovate right from the start, right? You still have to learn the basic skills from the master

大家講道理

If the constructor is overridden in a subclass, the constructor of the subclass will be called. If not, the constructor of its parent class will be called. If the constructor of the parent class is not called in the constructor of the subclass. Then the constructor of the parent class will not be called in the child class

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template