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


Groups > comp.lang.python > #73268

Re: Question about asyncio

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.025
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'result,': 0.07; 'subject:Question': 0.07; 'caller': 0.09; 'iterate': 0.09; 'itself.': 0.14; 'coroutines': 0.16; 'invoking': 0.16; 'iterating': 0.16; 'modified.': 0.16; 'simplest': 0.16; 'suspend': 0.16; 'task.': 0.16; 'wrote:': 0.18; '(the': 0.22; 'choices': 0.24; "shouldn't": 0.24; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'on,': 0.29; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; '13,': 0.31; 'yourself.': 0.31; 'option': 0.32; 'run': 0.32; 'another': 0.32; 'fri,': 0.33; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'executing': 0.36; 'changing': 0.37; 'application': 0.37; 'being': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'entire': 0.61; 'simple': 0.61; 'happen': 0.63; 'telling': 0.64; 'different': 0.65; 'frank': 0.68; 'behavior': 0.77; 'scheduling': 0.84; 'either:': 0.91
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 :content-type; bh=rJTFOzJXDkdifHDxLbl4Ycuwi5ZM5d0suBgnXAoJX0E=; b=m3IYNa6Ejmqvg4gIzYHIDdGqjZFyPBeGNi+EczyA8HhsQml4+7+ID0RzT31OeVjssz dPVQeY35e1Nd5Ks+6WTcRa8rg9NUmiWGn9yvsybi8I8n10w0jZXoUWJcMBFD0abGEycK aFLyH2yxO6Di2AWJyUgObK+eqPQTWcLXRaZ1VMR+RgDAHMXB/UE2OigdGT++k/DSGuWS gFO53rODdCUelomqcFIm6CzGszIVlLc35FVlRLl5SlFBffw5pFuy4/zOOeuP3AkpGe6N liXK/U3zDt24n0EIDX9X7ArJ4fepGqWLmvkqDYAaUXhWOoTV791wwKSsvrkS/2DJmGBd EI6Q==
X-Received by 10.236.65.227 with SMTP id f63mr5485833yhd.13.1402674964545; Fri, 13 Jun 2014 08:56:04 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <lneo24$1lk$1@ger.gmane.org>
References <lneo24$1lk$1@ger.gmane.org>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Fri, 13 Jun 2014 09:55:23 -0600
Subject Re: Question about asyncio
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11058.1402674972.18130.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402674972 news.xs4all.nl 2959 [2001:888:2000:d::a6]:37140
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73268

Show key headers only | View raw


On Fri, Jun 13, 2014 at 5:42 AM, Frank Millman <frank@chagford.com> wrote:
> Now I want to use the functionality of asyncio by using a 'yield from' to
> suspend the currently executing function at a particular point while it
> waits for some information. I find that adding 'yield from' turns the
> function into a generator, which means that the caller has to iterate over
> it.

Hold up; you shouldn't be iterating over the coroutines yourself.
Your choices for invoking an asyncio coroutine are either: 1) schedule
it (the simplest way to do this is by calling asyncio.async); or 2)
using 'yield from' in another coroutine that is already being run as a
task.

> I can avoid that by telling the caller to 'yield from' the generator,
> but then *its* caller has to be modified. Now I find I am going through my
> entire application and changing every function into a coroutine by
> decorating it with @asyncio.coroutine, and changing a simple function call
> to a 'yield from'.

If the caller needs to wait on the result, then I don't think you have
another option but to make it a coroutine also.  However if it doesn't
need to wait on the result, then you can just schedule it and move on,
and the caller doesn't need to be a coroutine itself.  Just be aware
that this could result in different behavior from the threaded
approach, since whatever the function does after the scheduling will
happen before the coroutine is started rather than after.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Question about asyncio Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-13 09:55 -0600

csiph-web