Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

Commit e6e4041

Browse files
sylvainbvxgmichel
authored andcommitted
Use asyncio.gather instead of asyncio.ensure_future
The asyncio.ensure_future is not introduced in the previous examples.
1 parent af3b227 commit e6e4041

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

examples/producer_consumer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ async def consume(queue):
3232

3333
loop = asyncio.get_event_loop()
3434
queue = asyncio.Queue(loop=loop)
35-
asyncio.ensure_future(produce(queue, 10), loop=loop)
36-
loop.run_until_complete(consume(queue))
35+
producer_coro = produce(queue, 10)
36+
consumer_coro = consume(queue)
37+
loop.run_until_complete(asyncio.gather(producer_coro, consumer_coro))
3738
loop.close()

0 commit comments

Comments
 (0)