我的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'。 –