python中Threading模块用于提供线程相关的操作,线程是应用程序中执行的最小单元。

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 
 4 import threading
 5 import time
 6   
 7 def show(arg):
 8     time.sleep(1)
 9     print 'thread'+str(arg)
10   
11 for i in range(10):
12     #调用构造函数,实例化对象,第1个参数是线程执行的函数,第2个参数是函数参数
13     t = threading.Thread(target=show, args=(i,))
14     #线程准备就绪,等待CPU调度
15     t.start()  
16   
17 print 'main thread stop'
View Code

相关文章: