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 the return order of AsyncHTMLSession.run #531

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

acjh
Copy link

@acjh acjh commented Feb 4, 2023

Fixes #480
Stack Overflow question: AsyncHTMLSession returns responses list disorderly! How to sort or make list ordered?

done is a set, which is unordered.

Since AsyncHTMLSession.run calls run_until_complete(...), all tasks are in done, so we can just iterate tasks.

This change is backward-compatible.

done is not in the order of completion, unlike asyncio.as_completed, so there is no loss of information in this change.

From https://github.com/python/cpython/blob/4cc63e0/Lib/asyncio/tasks.py#L535-L541:

    done, pending = set(), set()
    for f in fs:
        if f.done():
            done.add(f)
        else:
            pending.add(f)
    return done, pending

where fs = set(tasks).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Help me understanding the return order of asession.run
1 participant