标签:idt process http time 多线程 子类 blog for 有一个
#-*- coding:utf-8 -*- import time def main(): print("我错了。。。") time.sleep(1) if __name__ == "__main__": start_time = time.time() for i in range(5): main() end_time = time.time() print("the run time is %s"%(end_time-start_time))
#-*- coding:utf-8 -*- from threading import Thread import time #1.如果多个线程执行的都是同一个函数的话,各自之间不会有影响,各是各的 def main(): print("我错了。。。") time.sleep(1) if __name__ == "__main__": start_time = time.time() for i in range(5): # Process(target=test) Process进程完成多任务 t = Thread(target=main) t.start() end_time = time.time() print("the run time is %s"%(end_time-start_time))
#coding=utf-8 import threading import time class MyThread(threading.Thread): def run(self): for i in range(3): time.sleep(1) msg = "I‘m "+self.name+‘ @ ‘+str(i) #name属性中保存的是当前线程的名字 print(msg) if __name__ == ‘__main__‘: t = MyThread() t.start()
#coding=utf-8 import threading import time class MyThread(threading.Thread): def run(self): for i in range(3): time.sleep(1) msg = "I‘m "+self.name+‘ @ ‘+str(i) print(msg) def test(): for i in range(5): t = MyThread() t.start() if __name__ == ‘__main__‘:
标签:idt process http time 多线程 子类 blog for 有一个
原文地址:http://www.cnblogs.com/venicid/p/7966129.html