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()
posted @ 2022-01-12 14:48  mingtian是吧  阅读(20)  评论(0编辑  收藏  举报