Below is a piece of code which takes a list of IPs, pings the hosts and returns (prints) the list for "Alive" and "Dead". Any feedback on what can be done better is welcomed, mainly, speed and reliability! Would you accept it as production code? What about try/except blocks and logging?
import subprocess
from multiprocessing import Pool, cpu_count
hosts = ('127.0.0.1', 'google.com', '127.0.0.2', '10.1.1.1')
def ping(host):
ret = subprocess.call(['ping', '-c', '5', '-W', '3', host], stdout=open('/dev/null', 'w'), stderr=open('/dev/null', 'w'))
return ret == 0
host_list = {"Alive":[], "Dead":[]}
host_stat = {True: host_list["Alive"], False: host_list["Dead"]}
p = Pool(cpu_count())
[host_stat[success].append(host) for host, success in zip(hosts, p.map(ping, hosts))]
print host_stat