码迷,mamicode.com
首页 > 编程语言 > 详细

【Python】多线程

时间:2017-04-15 23:55:41      阅读:397      评论:0      收藏:0      [点我收藏+]

标签:sel   elf   sleep   name   log   线程   art   tin   多线程   

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】多线程

标签:sel   elf   sleep   name   log   线程   art   tin   多线程   

原文地址:http://www.cnblogs.com/verstin/p/6716268.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!