其他分享
首页 > 其他分享> > day40 线程

day40 线程

作者:互联网

目录

一、开启线程的两种方式

from threading import Thread
import time

# 直接创建
def func():
    time.sleep(1)
    print('aaa')


if __name__ == '__main__':
    t = Thread(target=func)
    t.start()
    print('xxx')


# 类继承创建
class MyThread(Thread):
    def __init__(self,name):
        super().__init__()
        self.name = name
    def run(self):
        print('start....')
        print(self.name)

if __name__ == '__main__':
    t = MyThread('hz')
    t.start()
    print('

标签:__,Thread,线程,time,print,import,day40
来源: https://www.cnblogs.com/hz2lxt/p/12768491.html