Dec-26-2019, 09:05 AM
Using
Here a test.
Running this it wait 20-sec then do ping one bye one.
call
or run
it will not run subprocesses in parallel.Popen
release so it run in parallel.Here a test.
Running this it wait 20-sec then do ping one bye one.
from subprocess import Popen, call, run # ping -c 4 google.com ## Linux commands = [ 'sleep 20', 'ping -n 4 google.com', 'ping -n 4 cnn.com' ] # Try run in parallel processes = [call(cmd, shell=True) for cmd in commands] ''' for p in processes: p.wait()'''Now you see that ping and sleep start in parallel all at once.
from subprocess import Popen, call, run # ping -c 4 google.com ## Linux commands = [ 'sleep 20', 'ping -n 4 google.com', 'ping -n 4 cnn.com' ] # Try run in parallel processes = [Popen(cmd, shell=True) for cmd in commands] ''' for p in processes: p.wait()'''