Skip to content

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