From 97186b1d19a3854559062729daaff937e9ef493e Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Wed, 23 Nov 2022 16:58:46 -0600 Subject: [PATCH] Remove use of blocking IO in an async function --- changelogs/fragments/13-no-blocking-io-async.yaml | 4 ++++ src/antsibull_core/galaxy.py | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/13-no-blocking-io-async.yaml diff --git a/changelogs/fragments/13-no-blocking-io-async.yaml b/changelogs/fragments/13-no-blocking-io-async.yaml new file mode 100644 index 0000000..646b9ce --- /dev/null +++ b/changelogs/fragments/13-no-blocking-io-async.yaml @@ -0,0 +1,4 @@ +--- +bugfixes: + - Remove use of blocking IO in an async function + (https://github.com/ansible-community/antsibull-core/pull/13/). diff --git a/src/antsibull_core/galaxy.py b/src/antsibull_core/galaxy.py index 15e18e4..79bd9d2 100644 --- a/src/antsibull_core/galaxy.py +++ b/src/antsibull_core/galaxy.py @@ -10,6 +10,7 @@ import typing as t from urllib.parse import urljoin +import aiofiles import semantic_version as semver from . import app_context @@ -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