Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: (Python 3.5) Asyncio and an attempt to run loop.run_until_complete() from within a running loop Date: Sat, 9 Apr 2016 09:38:05 -0600 Lines: 14 Message-ID: References: <33e44698-2625-47c4-9595-00a8c79f27ad@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de Ub59My4wb4UvACdBijg/eQAY2UAG6s+pofSLKpB+e+xA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:209.85.223': 0.03; 'subject:Python': 0.05; 'loop.': 0.09; 'def': 0.13; '2016': 0.16; 'alexander': 0.16; 'async': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'redundant.': 0.16; 'subject:run': 0.16; 'wrote:': 0.16; 'am,': 0.23; 'sat,': 0.23; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'becomes': 0.30; 'subject:) ': 0.32; 'received:google.com': 0.35; 'list,': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'received:209': 0.38; 'mean': 0.38; 'does': 0.39; 'subject:from': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'different': 0.63; 'here': 0.66; 'results': 0.66; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=y1R7zbagk5UTWvcuNAy/VbV3fq+Hah1e6maZAMIQhqI=; b=MvOlrK8vKY19XHc623H4vKj0wN7zxy4ea5kiiBdPynSDX2J9MuH1zLR6X03oqxPHaw E3Lnamqy7bJeo1ApgKBCdi2mvZvyVRkXoaF13ZWTEmTZLmXAI8azhLUMjcetgGL/4QZC Q3XDfQow02waQYhkSjeDPhoTaBMVi296YZg2msbNJKdVqOxLn7ndpN9+reCsjshZeC8a mEK70JM1cI1af8xAnnW+wIvbQTytY8b0ZlaOuzVHJNqxl2/cHlpkGpBeTOUvYBlsKLR3 WhDNrTyox2oxf0LyaSsRayfh2LL1igLAVWffcajET4dnahNYsYgOQrpeozJ8Dtqr/0J3 P4/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=y1R7zbagk5UTWvcuNAy/VbV3fq+Hah1e6maZAMIQhqI=; b=kNSbFggQqQ9dBfaQXKs72hjmyevHQghLDostPUZoRwLrp3NYM1HMRRecEogk2nDiuQ avWEccWc4f4hCAzvFR/x6ZMt5j5YPAbneZly++JjRJCL9ZGYOZ2N9+hFQ4c0IkZSNYNC UpGnEiRrgx65hIBWqefGKhHmiZHZAfiP1MuU4J47gphn46xb+seCDiwkZHPfbLd2VeBz DC6yQ9SMD6IUWgdxBbNwtxesj3YZadrLoP3zJLn3YO6U0hArgUWq3QMs7Z1lSUwkgsV6 H0P4jET2ijGDLSoAMSlr3JmQZUK4ca6jTbfYrpWH9ErlK47eY0KZePHUv8PbugwwPu5y 6Vhg== X-Gm-Message-State: AD7BkJJViDGTAKfGJ/J5Ig/X6FHHuZM0DeUNVaXQOUnj/bvIjuizIUwlDnm67PrV/oV1SUBn/LvVvlEVfuR5qQ== X-Received: by 10.107.135.75 with SMTP id j72mr15362330iod.111.1460216325293; Sat, 09 Apr 2016 08:38:45 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <33e44698-2625-47c4-9595-00a8c79f27ad@googlegroups.com> Xref: csiph.com comp.lang.python:106739 On Sat, Apr 9, 2016 at 9:14 AM, Ian Kelly wrote: > On Fri, Apr 8, 2016 at 5:54 PM, Alexander Myodov 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.