-1

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

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

2 Answers2

1

It worked by adding args in this line ...

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

The problem is that when you pass the simpleTest function as an argument, you are calling it. You should write the code like this:

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

Or using 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.

JeanExtreme002
  • 200
  • 3
  • 14