Currently I am getting MAC addresses from devices via Bluetooth and I pass these mac addresses one at a time to a method that calls a subprocess and assigns the output to a variable. With that variable I run some filtering functions to get a value from the command called in the subprocess. I then return that value if it finds it from the output.
What I would like to do is pass all mac addresses to the method at once and run them all at one time. How do I capture the output of each process and run my filtering script as the processes complete, and at the same time notify me if the process fails or errors.
Here is the current method that handles one mac at a time. Lets assume now that I am passing a list of mac addresses.
def getchan(mac): a = subprocess.Popen(["sdptool", "search","--bdaddr", mac, "OPUSH"], stdout = subprocess.PIPE).communicate()[0].split()[2:] if a==[]: print "ERROR" return "ERROR" else: count = 0 for item in a: if item == "Channel:": return a[count + 1] count += 1 return "Could not find the OPUSH channel" It should look something like
def getchan(macs): processes = set() for mac in macs: processes.add(subprocess.Popen(["sdptool", "search","--bdaddr", mac, "OPUSH"], stdout = subprocess.PIPE).communicate()[0].split()[2:]) #this is where I need the help Thank you for taking a look. Any help or clarification of Subprocesses would be much appreciated.