Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106712

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

X-Received by 10.140.221.134 with SMTP id r128mr7496185qhb.0.1460159655608; Fri, 08 Apr 2016 16:54:15 -0700 (PDT)
X-Received by 10.50.98.70 with SMTP id eg6mr155968igb.4.1460159655551; Fri, 08 Apr 2016 16:54:15 -0700 (PDT)
Path csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!7no643943qgj.0!news-out.google.com!u9ni855igk.0!nntp.google.com!nt3no9219721igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Fri, 8 Apr 2016 16:54:15 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=88.119.17.114; posting-account=AfnEQQoAAAAdYfMSipkQxdj7yfUGTnOb
NNTP-Posting-Host 88.119.17.114
User-Agent G2/1.0
MIME-Version 1.0
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>
Injection-Date Fri, 08 Apr 2016 23:54:15 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Received-Bytes 2396
X-Received-Body-CRC 3247743890
Xref csiph.com comp.lang.python:106712

Show key headers only | View raw


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 | NextNext in thread | Find similar | Unroll thread


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