python多线程(1)基础

import threading,time

def run(num):
  print 'Hi ,im aaa',num
  time.sleep(2)
  print '--->'


for i in range(5):
  t=threading.Thread(target=run,args=(i,))
  t.start()


#以下为结果
[root@localhost ptest]# python threadt.py 
Hi ,im aaa 0
Hi ,im aaa 1
Hi ,im aaa 2
Hi ,im aaa 3
Hi ,im aaa 4
--->
--->
--->
--->
--->

猜你喜欢

转载自886.iteye.com/blog/2323641