requests-html
requests-html copied to clipboard
Fix the return order of AsyncHTMLSession.run
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)
.