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

Remove use of blocking IO in an async function #13

Merged
merged 1 commit into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions changelogs/fragments/13-no-blocking-io-async.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
bugfixes:
- Remove use of blocking IO in an async function
(https://github.com/ansible-community/antsibull-core/pull/13/).
5 changes: 3 additions & 2 deletions src/antsibull_core/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import typing as t
from urllib.parse import urljoin

import aiofiles
import semantic_version as semver

from . import app_context
Expand Down Expand Up @@ -258,12 +259,12 @@ async def download(self, collection: str, version: t.Union[str, semver.Version],
if response.status == 404:
raise NoSuchCollection(f'No collection found at: {release_url}')

with open(download_filename, 'wb') as f:
async with aiofiles.open(download_filename, 'wb') as f:
lib_ctx = app_context.lib_ctx.get()
# TODO: PY3.8: while chunk := await response.content.read(lib_ctx.chunksize):
chunk = await response.content.read(lib_ctx.chunksize)
while chunk:
f.write(chunk)
await f.write(chunk)
chunk = await response.content.read(lib_ctx.chunksize)

# Verify the download
Expand Down