线程中父类重写及如何看当前线程

setDaemon(True)最好不要和重写父类写在一起
import threading
import time
import os
# lock=threading.Lock
class Walk(threading.Thread):
    # lock.acquire
    def __init__(self,num):
        super(Walk, self).__init__()
        self.num=num
    def run(self):
        # lock.acquire()
        for i in range(self.num):
            print('w',i,os.getpid)
        # lock.release()
            time.sleep(1)
        #
class Make(threading.Thread):
    def run(self):
        # lock.acquire()
        print('making')
        time.sleep(2)
        # lock.release()

if __name__ == '__main__':
    d=Walk(5)
    d.start()
    d.join()
    p=Make()
    p.start()

    print(threading.enumerate())
    print('主进程结束')
    exit()
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页