so I got this tricky situation which I need to execute few subprocess and be able to get each subprocess output. This is what I'm using atm:
output = Popen(cmd, stdout=PIPE, stderr=STDOUT)
output = output.communicate()[0]
Which works really well and also getting me errors, if there are any. Now I need to execute like 10 of those and be able to get the output of each one of them. I was wondering if there is a smooth way of doing that WITHOUT using multithreading.
subprocess.Popen
starts the child process asynchronously, only communicate
makes the operation synchronous.
So you just have to first launch all your children processes. Then depending on how you want to process their output, you can:
communicate
or wait
for each child command select
module. subprocess.poll
on child processes to know which have finished.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.