# Buggy code
def _upload_file_obj(
    self,
    file_obj: BytesIO,
    key: str,
    bucket_name: Optional[str] = None,
    replace: bool = False,
    encrypt: bool = False,
    acl_policy: Optional[str] = None,
) -> None:
    if not replace and self.check_for_key(key, bucket_name):
        raise ValueError(f"The key {key} already exists.")

    extra_args = self.extra_args
    if encrypt:
        extra_args["ServerSideEncryption"] = "AES256"
    if acl_policy:
        extra_args["ACL"] = acl_policy

    client = self.get_conn()
    client.upload_fileobj(file_obj, bucket_name, key, ExtraArgs=extra_args)


# Traceback (RuntimeError)
[2021-02-05 02:11:30,103] {hooks.py:210} DEBUG - Event needs-retry.s3.HeadObject: calling handler <botocore.retryhandler.RetryHandler object at 0x7f097f048110>
[2021-02-05 02:11:30,103] {retryhandler.py:187} DEBUG - No retry needed.
[2021-02-05 02:11:30,103] {hooks.py:210} DEBUG - Event needs-retry.s3.HeadObject: calling handler <bound method S3RegionRedirector.redirect_from_error of <botocore.utils.S3RegionRedirector object at 0x7f097f0293d0>>
[2021-02-05 02:11:30,103] {utils.py:1187} DEBUG - S3 request was previously to an accesspoint, not redirecting.
[2021-02-05 02:11:30,105] {utils.py:580} DEBUG - Acquiring 0
[2021-02-05 02:11:30,105] {futures.py:277} DEBUG - TransferCoordinator(transfer_id=0) cancel(cannot schedule new futures after interpreter shutdown) called
[2021-02-05 02:11:30,105] {s3_task_handler.py:193} ERROR - Could not write logs to s3://arn:aws:s3:us-west-2:<ACCOUNT>:accesspoint:<BUCKET,PATH>/2021-02-05T02:04:23.265117+00:00/1.log
Traceback (most recent call last):
File "/home/airflow/.local/lib/python3.7/site-packages/airflow/providers/amazon/aws/log/s3_task_handler.py", line 190, in s3_write
encrypt=conf.getboolean('logging', 'ENCRYPT_S3_LOGS'),
File "/home/airflow/.local/lib/python3.7/site-packages/airflow/providers/amazon/aws/hooks/s3.py", line 61, in wrapper
return func(*bound_args.args, **bound_args.kwargs)
File "/home/airflow/.local/lib/python3.7/site-packages/airflow/providers/amazon/aws/hooks/s3.py", line 90, in wrapper
return func(*bound_args.args, **bound_args.kwargs)
File "/home/airflow/.local/lib/python3.7/site-packages/airflow/providers/amazon/aws/hooks/s3.py", line 547, in load_string
self._upload_file_obj(file_obj, key, bucket_name, replace, encrypt, acl_policy)
File "/home/airflow/.local/lib/python3.7/site-packages/airflow/providers/amazon/aws/hooks/s3.py", line 638, in _upload_file_obj
client.upload_fileobj(file_obj, bucket_name, key, ExtraArgs=extra_args)
File "/home/airflow/.local/lib/python3.7/site-packages/boto3/s3/inject.py", line 538, in upload_fileobj
extra_args=ExtraArgs, subscribers=subscribers)
File "/home/airflow/.local/lib/python3.7/site-packages/s3transfer/manager.py", line 313, in upload
call_args, UploadSubmissionTask, extra_main_kwargs)
File "/home/airflow/.local/lib/python3.7/site-packages/s3transfer/manager.py", line 471, in _submit_transfer
main_kwargs=main_kwargs
File "/home/airflow/.local/lib/python3.7/site-packages/s3transfer/futures.py", line 467, in submit
future = ExecutorFuture(self._executor.submit(task))
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 165, in submit
raise RuntimeError('cannot schedule new futures after '
RuntimeError: cannot schedule new futures after interpreter shutdown

# Fixed code
def _upload_file_obj(
    self,
    file_obj: BytesIO,
    key: str,
    bucket_name: Optional[str] = None,
    replace: bool = False,
    encrypt: bool = False,
    acl_policy: Optional[str] = None,
) -> None:
    if not replace and self.check_for_key(key, bucket_name):
        raise ValueError(f"The key {key} already exists.")

    extra_args = self.extra_args
    if encrypt:
        extra_args["ServerSideEncryption"] = "AES256"
    if acl_policy:
        extra_args["ACL"] = acl_policy

    client = self.get_conn()
    client.upload_fileobj(
        file_obj,
        bucket_name,
        key,
        ExtraArgs=extra_args,
        Config=self.transfer_config,
    )