Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106712
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2016-04-08 16:54 -0700 |
| Message-ID | <33e44698-2625-47c4-9595-00a8c79f27ad@googlegroups.com> (permalink) |
| Subject | (Python 3.5) Asyncio and an attempt to run loop.run_until_complete() from within a running loop |
| From | Alexander Myodov <amyodov@gmail.com> |
Hello. TLDR: how can I use something like loop.run_until_complete(coro), to execute a coroutine synchronously, while the loop is already running? More on this: I was trying to create an aio_map(coro, iterable) function (which would asynchronously launch a coroutine for each iteration over iterable, and collect the data; similary to gevent.pool.Group.imap() from another async world), but stuck while attempting to make it well both from outside the async event loop and from inside one - any help? My code is at http://paste.pound-python.org/show/EQvN2cSDp0xqXK56dUPy/ - and I stuck around lines 22-28, with the problem that loop.run_until_complete() cannot be executed when the loop is running already (raising "RuntimeError: Event loop is running."). Is it normal? and why is it so restrictive? And what can I do to wait for `coros` Future to be finished? I tried various mixes of loop.run_forever() and even loop._run_once() there, but was not able to create a stable working code. Am I doing something completely wrong here? Am I expected to create a totally new event loop for synchronously waiting for the Future, if the current event loop is running - and if so, won't the previous event loop miss any its events? Thank you in advance. Alexander
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
(Python 3.5) Asyncio and an attempt to run loop.run_until_complete() from within a running loop Alexander Myodov <amyodov@gmail.com> - 2016-04-08 16:54 -0700 Re: (Python 3.5) Asyncio and an attempt to run loop.run_until_complete() from within a running loop "Frank Millman" <frank@chagford.com> - 2016-04-09 07:08 +0200 Re: (Python 3.5) Asyncio and an attempt to run loop.run_until_complete() from within a running loop Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-09 09:14 -0600 Re: (Python 3.5) Asyncio and an attempt to run loop.run_until_complete() from within a running loop Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-09 09:38 -0600
csiph-web