Skip to content

Commit

Permalink
fix: Fixing an issue with unawaited coroutines (#166)
Browse files Browse the repository at this point in the history
Fixing an issue with unawaited coroutines when the download command exited abnormal.

* Refactor consume function and queue_job function

* doc: Update CHANGELOG.md
  • Loading branch information
mkb79 authored Nov 15, 2023
1 parent cda40c6 commit 8f8eacf
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 59 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Bugfix

- Avoid tqdm progress bar interruption by logger’s output to console.
- Fixing an issue with unawaited coroutines when the download command exited abnormal.

### Misc

Expand Down
118 changes: 59 additions & 59 deletions src/audible_cli/cmds/cmd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ async def download_aaxc(

async def consume(queue, ignore_errors):
while True:
item = await queue.get()
cmd, kwargs = await queue.get()
try:
await item
await cmd(**kwargs)
except Exception as e:
logger.error(e)
if not ignore_errors:
Expand Down Expand Up @@ -450,73 +450,73 @@ def queue_job(

if get_cover:
for cover_size in cover_sizes:
queue.put_nowait(
download_cover(
client=client,
output_dir=output_dir,
base_filename=base_filename,
item=item,
res=cover_size,
overwrite_existing=overwrite_existing
)
)
cmd = download_cover
kwargs = {
"client": client,
"output_dir": output_dir,
"base_filename": base_filename,
"item": item,
"res": cover_size,
"overwrite_existing": overwrite_existing
}
queue.put_nowait((cmd, kwargs))

if get_pdf:
queue.put_nowait(
download_pdf(
client=client,
output_dir=output_dir,
base_filename=base_filename,
item=item,
overwrite_existing=overwrite_existing
)
)
cmd = download_pdf
kwargs = {
"client": client,
"output_dir": output_dir,
"base_filename": base_filename,
"item": item,
"overwrite_existing": overwrite_existing
}
queue.put_nowait((cmd, kwargs))

if get_chapters:
queue.put_nowait(
download_chapters(
output_dir=output_dir,
base_filename=base_filename,
item=item,
quality=quality,
overwrite_existing=overwrite_existing
)
)
cmd = download_chapters
kwargs = {
"output_dir": output_dir,
"base_filename": base_filename,
"item": item,
"quality": quality,
"overwrite_existing": overwrite_existing
}
queue.put_nowait((cmd, kwargs))

if get_annotation:
queue.put_nowait(
download_annotations(
output_dir=output_dir,
base_filename=base_filename,
item=item,
overwrite_existing=overwrite_existing
)
)
cmd = download_annotations
kwargs = {
"output_dir": output_dir,
"base_filename": base_filename,
"item": item,
"overwrite_existing": overwrite_existing
}
queue.put_nowait((cmd, kwargs))

if get_aax:
queue.put_nowait(
download_aax(
client=client,
output_dir=output_dir,
base_filename=base_filename,
item=item,
quality=quality,
overwrite_existing=overwrite_existing,
aax_fallback=aax_fallback
)
)
cmd = download_aax
kwargs = {
"client": client,
"output_dir": output_dir,
"base_filename": base_filename,
"item": item,
"quality": quality,
"overwrite_existing": overwrite_existing,
"aax_fallback": aax_fallback
}
queue.put_nowait((cmd, kwargs))

if get_aaxc:
queue.put_nowait(
download_aaxc(
client=client,
output_dir=output_dir,
base_filename=base_filename,
item=item,
quality=quality,
overwrite_existing=overwrite_existing
)
)
cmd = download_aaxc
kwargs = {
"client": client,
"output_dir": output_dir,
"base_filename": base_filename,
"item": item,
"quality": quality,
"overwrite_existing": overwrite_existing
}
queue.put_nowait((cmd, kwargs))


def display_counter():
Expand Down

0 comments on commit 8f8eacf

Please sign in to comment.