首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Python 多线程容易例子

2012-10-14 
Python 多线程简单例子http://blog.csdn.net/ghostfromheaven/article/details/7039310import threadingim

Python 多线程简单例子
http://blog.csdn.net/ghostfromheaven/article/details/7039310

import threadingimport timeclass 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 100msMyThread(1, 10).start();#start the 1st threadMyThread(2, 10).start();#start the 2nd threadMyThread(3, 10).start();#start the 3rd thread


热点排行