s3upload_3.py 678 B

123456789101112131415161718
  1. def put_to_s3(run_event: Event, client, queue: Queue, bucket, acl, remove_files):
  2. while not queue.empty() and run_event.is_set():
  3. filepath, object_key = queue.get()
  4. try:
  5. client.upload_file(
  6. filepath, bucket, object_key,
  7. ExtraArgs={'ACL': acl}
  8. )
  9. except ClientError as e:
  10. print('Error occurred while uploading: {}'.format(str(e)))
  11. continue
  12. if remove_files:
  13. os.remove(filepath)
  14. print('uploaded: {}\nkey: {}\n{}\n'.format(
  15. filepath,
  16. object_key,
  17. 'removed: {}'.format(filepath) if remove_files else ''
  18. ))