threading 模块
import threading
import queue
import os
q= queue.Queue()
for i in range(1,255):
q.put(i)
try:
f = open('1.txt','a')
def fun01(num):
result=os.popen('ping 168.101.1.%d' %num)
f.wite(result)
print(threading.current_thread().getName())
finally:
f.close()
for i in range(100):
n=q.get()
t=threading.Thread(target=fun01,args=(n,))
t.start()