Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python)': 0.05; 'debug': 0.07; 'classes.': 0.09; 'function,': 0.09; 'pep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'section,': 0.09; 'used.': 0.09; 'wrong,': 0.09; 'python': 0.11; 'jan': 0.12; 'frankly': 0.16; 'merely': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'send,': 0.16; 'skipping': 0.16; 'subject:between': 0.16; 'subject:tasks': 0.16; 'suspend': 0.16; 'tasks,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'header:User-Agent:1': 0.23; 'paul': 0.24; "i've": 0.25; 'task': 0.26; '(for': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'correct': 0.29; 'rest': 0.29; 'am,': 0.29; "i'm": 0.30; 'code': 0.31; 'run': 0.32; 'subject:the': 0.34; 'basic': 0.35; 'definition': 0.35; 'but': 0.35; 'really': 0.36; 'described': 0.36; 'subject:?': 0.36; 'detail': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'read': 0.60; 'future': 0.60; 'simple': 0.61; 'more': 0.64; 'situation': 0.65; 'details': 0.65; 'within': 0.65; 'between': 0.67; 'close': 0.67; 'believe': 0.68; 'complex,': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: asyncio: What is the difference between tasks, futures, and coroutines? Date: Tue, 05 May 2015 13:15:37 -0400 References: <344fd8f6-75c1-4b7d-888d-c5c9d4498ec3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-98-114-97-173.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: <344fd8f6-75c1-4b7d-888d-c5c9d4498ec3@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430846157 news.xs4all.nl 2891 [2001:888:2000:d::a6]:51663 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89979 On 5/5/2015 11:22 AM, Paul Moore wrote: > I'm working my way through the asyncio documentation. I have got to > the "Tasks and coroutines" section, but I'm frankly confused as to > the difference between the various things described in that section: > coroutines, tasks, and futures. > > I think can understand a coroutine. Correct me if I'm wrong, but it's > roughly "something that you can run which can suspend itself". The simple answer is that a coroutine within asyncio is a generator used as a (semi)coroutine rather than merely as an iterator. IE, the send, throw, and close methods are used. I believe PEP 492 will change that definition (for Python) to any object with with those methods. However, if an asyncio coroutine is the result of the coroutine decorator, the situation is more complex, as the result is either a generator function, a coro function that can wrap any function, or a debug wrapper. Details in asyncio/coroutine.py. > I concede that I've not read the rest of the asyncio documentation in > much detail yet, and I'm skipping everything to do with IO (I want to > understand the "async" bit for now, not so much the "IO" side). But I > don't really want to dive into the details while I am this hazy on > the basic concepts. You might try reading the Python code for the task and future classes. asyncio/futures.py, asyncio/tasks.py -- Terry Jan Reedy