(Python 3.5) Asyncio and an attempt to run loop.run_until_complete() from within a running loop

Ian Kelly ian.g.kelly at gmail.com
Sat Apr 9 11:38:05 EDT 2016


On Sat, Apr 9, 2016 at 9:14 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Fri, Apr 8, 2016 at 5:54 PM, Alexander Myodov <amyodov at gmail.com> wrote:
> This does mean that the pattern for calling aio_map from outside the
> event loop is different from calling it inside the event loop. Your
> main_loop coroutine becomes (note the addition of the "await"):
>
> async def main_loop(loop):
>     results = list(await aio_map(fetch_aio, range(5)))
>     assert(results == [{'aio_arg': '0'}, {'aio_arg': '1'}, {'aio_arg':
> '2'}, {'aio_arg': '3'}, {'aio_arg': '4'}]), results
>     print('Assert ok!')

As a final afterthought, note that the result of asyncio.gather is
already a list, so wrapping it in a list() call here is redundant.



More information about the Python-list mailing list