ITeye博客

Python 多线程简单例子

GhostFromheaven · 2011-12-04 13:58 · Python2.7 · 编程语言 · GhostFromHeaven · python2.7 · Pytho2.x · LongXiong · Markdown

http://blog.csdn.net/ghostfromheaven/article/details/7039310


import threading
import time

class MyThread(threading.Thread):
    def __init__(self, threadnum, max):
        threading.Thread.__init__(self)
        
        self.threadnum = threadnum
        
        if (max < 0 ):
            self.max = 0
        else:
            self.max = max
    def run(self):
        for x in xrange(self.max):
            print "thread-%d %d" % (self.threadnum, x)
            time.sleep(0.1);#sleep 100ms

MyThread(1, 10).start();#start the 1st thread
MyThread(2, 10).start();#start the 2nd thread
MyThread(3, 10).start();#start the 3rd thread

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。