Use ThreadPool
Something like that
from multiprocessing.pool import ThreadPool
pool = ThreadPool()
pool.map(function, list_containing_args)
PS it works similar to multiprocess map.Each argument is given a new thread .You can specify the number of threads you want to spawn if you have limited resources or a big list
from multiprocessing.pool import ThreadPool
import subprocess
def func(ip):
c=subprocess.Popen("ping -c 3 "+ip, shell=True, stdout=subprocess.PIPE)
output, error= c.communicate()
return output
pool = ThreadPool()
for i in pool.map(func,["127.0.0.1", "www.google.com", "www.facebook.com"]):
print i
source
share