python multithreading (1) basics

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()


#The following is the result
[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
--->
--->
--->
--->
--->

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326553692&siteId=291194637