线程开启的两种方式

#第一种
from threading import Thread
import time
def task():
    print('线程 start')
    time.sleep(2)
    print('线程 end')

if __name__ == '__main__':
    t=Thread(target=task)
    t.start() # 告诉操作系统开一个线程
    print('主')
#第二种
from threading import Thread
import time

class Myt(Thread):
    def run(self):
        print('子线程 start')
        time.sleep(5)
        print('子线程 end')

t=Myt()
t.start()
print('主线程')
posted on 2019-09-17 15:02  黑糖A  阅读(271)  评论(0编辑  收藏  举报