########征服python############
1. 使用Thread创建线程
import thread
def run(n):
for i in range(n):
print(i)
thread.start_new_thread(run,(4,))
2 使用threading创建线程
import threading
class mythread(threading.Thread):
def __init__(self,num):
threading.Thread.__init__(self)
threading.Thread.num=num
def run(self):
print "I am",self.num
t1=mythread(1)
t2=mythread(2)
t3=mythread(5)
t1.start()
t2.start()
t3.start()
3
import threading
def run(x,y):
for i in range(x,y):
print(i)
t1=threading.Thread(target=run,args=(15,20))
t1.start()
t2=threading.Thread(target=run,args=(7,11))
t2.start()
############运行结果都很奇葩~~~我自己解释不了~~~只能直观感受一下~~~~~##############