| 
 
	积分3625贡献 精华在线时间 小时注册时间2014-10-21最后登录1970-1-1 
 | 
 
| 
一、多线程的基本操作
x
登录后查看更多精彩内容~您需要 登录 才可以下载或查看,没有帐号?立即注册 
  
 python多线程模块threading,用法与多进程multiProcessing几乎一样!
 对照参考:Python之进程的学习
 
 import threading
 
 def f(n):
 print('线程名:',threading.current_thread().name,[1]*n)
 
 if __name__=='__main__':
 #新建3个线程:
 thread1=threading.Thread(target=f,args=(2,),name='firstThread')
 thread2=threading.Thread(target=f,args=(4,))
 thread3=threading.Thread(target=f,args=(6,))
 
 thread1.start()
 thread2.start()
 thread3.start()
 
 thread1.join()
 thread2.join()
 thread3.join()
 
 
 #结果:
 # 线程名: firstThread [1, 1]
 # 线程名: Thread-1 [1, 1, 1, 1]
 # 线程名: Thread-2 [1, 1, 1, 1, 1, 1]
 
 
 | 
 |