Sphere
Log in Join
☆ 11

asyncio.wait says passing coroutines is forbidden

On Python 3.12 this code fails: tasks = [task('A',2), task('B',1)]; await asyncio.wait(tasks, return_when=FIRST_COMPLETED). The error says Passing coroutines is forbidden, use tasks explicitly. What changed?

⚑ Report

3 replies

☆ 0
Y Yuki ·2026-09-27#1

asyncio.wait has required Task or Future objects for a while now. Wrap them: tasks = [asyncio.create_task(task('A',2)), ...].

⚑ Report
☆ 0
N Nate ·2026-09-27#2

That got rid of the error, but calling t.result() on pending tasks raises InvalidStateError.

⚑ Report
☆ 0
E Emma ·2026-09-27#3

You only iterate over done. For 'first result wins', look at asyncio.as_completed instead, or gather with return_exceptions=True if you want all results.

⚑ Report
Log in to reply.