# Buggy code
def load_file(
    self,
    filename: str,
    key: str,
    bucket_name: Optional[str] = None,
    replace: bool = False,
    encrypt: bool = False,
    gzip: bool = False,
    acl_policy: Optional[str] = None,
) -> None:
    """
    Loads a local file to S3

    :param filename: name of the file to load.
    :type filename: str
    :param key: S3 key that will point to the file
    :type key: str
    :param bucket_name: Name of the bucket in which to store the file
    :type bucket_name: str
    :param replace: A flag to decide whether or not to overwrite the key
        if it already exists. If replace is False and the key exists, an
        error will be raised.
    :type replace: bool
    :param encrypt: If True, the file will be encrypted on the server-side
        by S3 and will be stored in an encrypted form while at rest in S3.
    :type encrypt: bool
    :param gzip: If True, the file will be compressed locally
    :type gzip: bool
    :param acl_policy: String specifying the canned ACL policy for the file being
        uploaded to the S3 bucket.
    :type acl_policy: str
    """
    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 gzip:
        with open(filename, "rb") as f_in:
            filename_gz = f_in.name + ".gz"
            with gz.open(filename_gz, "wb") as f_out:
                shutil.copyfileobj(f_in, f_out)
                filename = filename_gz
    if acl_policy:
        extra_args["ACL"] = acl_policy

    client = self.get_conn()
    client.upload_file(filename, 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 load_file(
    self,
    filename: str,
    key: str,
    bucket_name: Optional[str] = None,
    replace: bool = False,
    encrypt: bool = False,
    gzip: bool = False,
    acl_policy: Optional[str] = None,
) -> None:
    """
    Loads a local file to S3

    :param filename: name of the file to load.
    :type filename: str
    :param key: S3 key that will point to the file
    :type key: str
    :param bucket_name: Name of the bucket in which to store the file
    :type bucket_name: str
    :param replace: A flag to decide whether or not to overwrite the key
        if it already exists. If replace is False and the key exists, an
        error will be raised.
    :type replace: bool
    :param encrypt: If True, the file will be encrypted on the server-side
        by S3 and will be stored in an encrypted form while at rest in S3.
    :type encrypt: bool
    :param gzip: If True, the file will be compressed locally
    :type gzip: bool
    :param acl_policy: String specifying the canned ACL policy for the file being
        uploaded to the S3 bucket.
    :type acl_policy: str
    """
    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 gzip:
        with open(filename, "rb") as f_in:
            filename_gz = f_in.name + ".gz"
            with gz.open(filename_gz, "wb") as f_out:
                shutil.copyfileobj(f_in, f_out)
                filename = filename_gz
    if acl_policy:
        extra_args["ACL"] = acl_policy

    client = self.get_conn()
    client.upload_file(
        filename, bucket_name, key, ExtraArgs=extra_args, Config=self.transfer_config
    )