首页 > 解决方案 > mininet中的线程ping

问题描述

我想同时启动两台或多台主机,以便在 mininet 中使用 python ping 其他两台主机,我这样做但不起作用

def simpleTest(h1,h2): 

    print (h1.cmd('ping -c5 %s' h2.IP()))

和主要:

if __name__ == '__main__':
    net = Mininet(...)
    threads= 3 # three threads
    #....codes...... 
    for i in range(1, threads):
        hostsrc=net.hosts[i]
        hostdest=net.hosts[i+4]
        thread = threading.Thread(target=simpleTest(hostsrc,hostdest))
        jobs.append(thread)

    for j in jobs:
        j.start()
    for j in jobs:
        j.join()
    """
    codes ...
    """

任何解决方案请...

标签: pythonmultithreadingpingsdnmininet

解决方案


它通过在这一行中添加 args 来工作......

        thread = threading.Thread(target=simpleTest, args=(hostsrc,hostdest,))

推荐阅读