简体   繁体   English

mininet中的线程ping

[英]Threading ping in mininet

I want to launch two or many hosts simultaneously for pinging two others hosts with python in mininet, i do that and doesn't work我想同时启动两个或多个主机,以便在 mininet 中使用 python ping 其他两个主机,我这样做了,但不起作用

def simpleTest(h1,h2): 

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

and main :和主要:

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 ...
    """

Any solution for that please ...任何解决方案请...

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

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

The problem is that when you pass the simpleTest function as an argument, you are calling it.问题在于,当您将simpleTest函数作为参数传递时,您正在调用它。 You should write the code like this:你应该像这样编写代码:

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

Or using lambda:或者使用 lambda:

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

The code you wrote passed the value None to the target parameter, since the simpleTest function returns no value, so nothing happened when calling the start method.您编写的代码将值 None 传递给target参数,因为simpleTest函数没有返回值,因此在调用start方法时什么也没发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM