我的Python应用程序为AWS CLI S3上传创建了一个子进程。Python为S3上传生成了AWS CLI进程,并且变得非常慢
command = 'aws s3 sync /tmp/tmp_dir s3://mybucket/tmp_dir'
# spawn the process
sp = subprocess.Popen(
shlex.split(str(command)),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# wait for a while
sp.wait()
out, err = sp.communicate()
if sp.returncode == 0:
logger.info("aws return code: %s", sp.returncode)
logger.info("aws cli stdout `{}`".format(out))
return
# handle error
/tmp/tmp_dir
是〜0.5Gb并包含约100个文件。 上传过程需要约25分钟,这是非常缓慢的。
如果我直接运行AWS命令(不使用Python),它只需不到1分钟。
怎么了?任何帮助表示赞赏。
Python SDK现在不提供相同的功能。我正在使用'sync'。这可能会更好,但方式更费时。你能提供一个代码来避免管道阻塞的例子吗?谢谢。 –
嗯,是的,我明白你的意思是同步(递归拷贝dir)没有被执行。这里有一个我发现可能有用的要点:https://gist.github.com/SavvyGuard/6115006#file-botos3upload-py-L30 –
另外我编辑了我的答案,建议另外使用'subprocess'。 –