Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix coroutine function Callback #357

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions aioboto3/s3/inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ async def upload_fileobj(
Bucket: str,
Key: str,
ExtraArgs: Optional[Dict[str, Any]] = None,
Callback: Optional[Callable[[int], None]] = None,
Callback: Optional[TransferCallback] = None,
Config: Optional[S3TransferConfig] = None,
Processing: Callable[[bytes], bytes] = None
):
Expand Down Expand Up @@ -378,7 +378,10 @@ async def fileobj_read(num_bytes: int) -> bytes:
**kwargs
)
if Callback:
Callback(len(initial_data))
if inspect.iscoroutinefunction(Callback):
await Callback(len(initial_data))
else:
Callback(len(initial_data))
return

# File bigger than threshold, start multipart upload
Expand Down Expand Up @@ -423,7 +426,10 @@ async def uploader() -> int:
# Call the callback, if it blocks then not good :/
if Callback:
try:
Callback(current_bytes)
if inspect.iscoroutinefunction(Callback):
await Callback(current_bytes)
else:
Callback(current_bytes)
except: # noqa: E722
pass

Expand Down