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><code>os.system</code> is not patched, but <a href="https://docs.python.org/3/library/subprocess.html#subprocess.call" rel="nofollow"><code>subprocess.call</code></a> is patched; Replace <code>os.system</code> with <code>subprocess.call</code> (You can also use <a href="https://docs.python.org/3/library/subprocess.html#subprocess.call" rel="nofollow"><code>subprocess.run</code></a> if you are using Python 3.5+)</p>

<pre><code>import subprocess

...

def print_head(i):
    switch = '192.168.182.170'
    response = subprocess.call("ping " + switch)
</code></pre>

python gevent