简体   繁体   中英

Unable to upload to Amazon S3 via python threads

Heres how I thread it.

t = Thread(target=s3_upload, args=(absolute_write_path,raw_unique_key))
t.start()

Heres the function thats called in threads.

def s3_upload(file_path,key):
    conn = S3.AWSAuthConnection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)

    #check if bucket exists, if not cr8 it
    if S3_BUCKET_CHECK:
        if not conn.check_bucket_exists(S3_BUCKET_NAME).status == 200:
            conn.create_located_bucket(S3_BUCKET_NAME, S3_LOCATION)

    orig_file = open(file_path, "r")
    obj = S3Object(orig_file.read())
    conn.put(S3_BUCKET_NAME, key, obj)
    os.remove(file_path)

If I don't run it in threads, it seem to work. But if I run in threads, it works up to the line where I do conn.put() and it does not print line from there onwards. Does anyone know why?

Thanks.

ok solved it. the problem was that the def daemon value for flask was True. changed it to false (which i assumed was the def) and now it works :)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM