parallel ping using gevent
<p>I am new to python and I am trying to run this code to want parallel ping of multiple machines.but I can not ping all IP concurrently. seems it run one after another .can some one please guide me on how can i ping multiple server concurrently.</p>

<pre><code>import gevent
import urllib2
import os
from gevent import monkey
monkey.patch_all()


def print_head(i):
    switch='192.168.182.170'
    response = os.system("ping -c 5 " + switch)


jobs = [gevent.spawn(print_head, i) for i  in range(1,10)]
gevent.joinall(jobs, timeout=2)
</code></pre>

<p>The problem is that <code>os.system("ping -c 5 " + switch)</code> is running synchronously, because the function is blocking. You should try to do it in different processes.</p>

<p>Here is a concurrent code that does the same.</p>

<pre><code>from multiprocessing import Process
import os

def print_head(i):
    switch='192.168.182.170'
    response = os.system("ping -c 5 " + switch)

processes = [Process(target=print_head, args=(i,)) for i in range(1,10)]
for process in processes:
    process.start()
</code></pre>

python gevent