def put_to_s3(run_event: Event, client, queue: Queue, bucket, acl, remove_files): while not queue.empty() and run_event.is_set(): filepath, object_key = queue.get() try: client.upload_file( filepath, bucket, object_key, ExtraArgs={'ACL': acl} ) except ClientError as e: print('Error occurred while uploading: {}'.format(str(e))) continue if remove_files: os.remove(filepath) print('uploaded: {}\nkey: {}\n{}\n'.format( filepath, object_key, 'removed: {}'.format(filepath) if remove_files else '' ))