I'm trying to write a python script which uses the subprocess module to copy files from one s3 bucket to another. However to improve performance I'm trying to run separate sync commands with different prefixes in parallel.
What I've tried so far the script doesn't terminate and I'm not sure the sub processes are running concurrently.
import subprocess
prefix = ['prefix1','prefix2','prefix3']
source_bucket = 's3://source'
dest_bucket = 's3://dest'
commands = []
for p in prefix:
command = 'aws s3 sync source_bucket' + p + ' dest_bucket'
commands.append(command)
procs = [subprocess.Popen(i, shell=True, stdout=subprocess.PIPE) for i in commands]
for p in procs:
p.wait()
Is there a better way of doing this? Any help is appreciated.