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

相关文章:

  • 2021-11-25
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2021-05-04
猜你喜欢
  • 2021-09-19
  • 2021-12-30
  • 2021-05-19
  • 2021-11-06
  • 2021-07-17
  • 2021-10-19
相关资源
相似解决方案