boto / s3transfer

Amazon S3 Transfer Manager for Python
Apache License 2.0
209 stars 133 forks source link

Shutdown exception #215

Closed emrahgunduz closed 3 years ago

emrahgunduz commented 3 years ago

I've been trying to determine a way to cancel any boto3 upload/download calls. When I was checking the underlying "manager" object in the S3Transfer, i found the "shutdown" method.

But calling this method results in an exception being thrown.

client = boto3.client( 's3' )
transfer = S3Transfer( client )
transfer.download_file( bucket, key, to_file )

# Call just after the download starts
transfer._manager.shutdown( True )

The thrown exception is

python-BaseException
Traceback (most recent call last):
  File "/opt/.../lib/python3.8/site-packages/s3transfer/futures.py", line 278, in cancel
    self._exception = exc_type(msg)
TypeError: 'str' object is not callable

From what I found, the shutdown command is calling a protected member. But the called method signature is different.

def shutdown(self, cancel=False, cancel_msg=''):
    self._shutdown(cancel, cancel, cancel_msg)

def _shutdown(self, cancel, cancel_msg, exc_type=CancelledError):

The location the shutdown call is here: https://github.com/boto/s3transfer/blob/960fc1617882b854b141e368c6b3fc4be6334847/s3transfer/manager.py#L588

emrahgunduz commented 3 years ago

Looks like this is already reported and a pull request sent.