Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Frank Millman" Newsgroups: comp.lang.python Subject: Re: asyncio - run coroutine in the background Date: Tue, 16 Feb 2016 15:52:01 +0200 Lines: 20 Message-ID: References: <8737sumpjl.fsf@elektro.pacujo.net> <87h9ha8lt0.fsf@jester.gateway.pace.com> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de RmWK8UdvIqWYeSnXuauPfQvWCG9qeHEP7HzdN15YZZqA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.033 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'coroutines': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'skip:n 70': 0.16; 'subject:run': 0.16; 'wrote': 0.23; 'attach': 0.23; 'header:In-Reply-To:1': 0.24; 'header:X-Complaints-To:1': 0.26; 'handling': 0.27; 'function': 0.28; '[1]': 0.32; 'url:python': 0.33; 'effort.': 0.33; 'facility': 0.33; 'schedule': 0.34; 'there': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'thank': 0.38; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'future': 0.60; 'url:3': 0.60; 'your': 0.60; 'frank': 0.72; 'await': 0.76; 'returns.': 0.84; 'task,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 197.89.68.71 In-Reply-To: X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 15.4.3502.922 X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3502.922 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103008 "Kevin Conway" wrote in message news:CAKF=+dim8wzPRvm86_V2W5-XSopCcHvgm0Hy8r4xeHDYzy_P4w@mail.gmail.com... > > If you're handling coroutines there is an asyncio facility for "background > tasks". The ensure_future [1] will take a coroutine, attach it to a Task, > and return a future to you that resolves when the coroutine is complete. > The coroutine you schedule with that function will not cause your current > coroutine to wait unless you await the future it returns. > > [1] > https://docs.python.org/3/library/asyncio-task.html#asyncio.ensure_future > Thank you Kevin! That works perfectly, and is much neater than my effort. Frank