首页 > 代码库 > 【Python】多线程
【Python】多线程
import threading import time class myThread (threading.Thread): #继承父类threading.Thread def __init__(self, threadID, name): threading.Thread.__init__(self) self.name = name def run(self): #把要执行的代码写到run函数里面 线程在创建后会直接运行run函数 while 1: print("Starting " + self.name) time.sleep(1) # 创建新线程 thread1 = myThread(1, "this is thread1") thread2 = myThread(2, "this is thread2") thread3 = myThread(3, "this is thread3") # 开启线程 thread1.start() thread2.start() thread3.start()
【Python】多线程
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。