[Python-Dev] Importance of "async" keyword
Sven R. Kunze
srkunze at mail.de
Fri Jun 26 15:48:36 CEST 2015
On 25.06.2015 21:11, Andrew Svetlov wrote:
>> Another issue that bothers me, is code reuse. Independent from whether the
>> 'async def' makes sense or not, it would not allow us to reuse asyncio
>> functions as if they were normal functions and vice versa (if I understood
>> that correctly). So, we would have to implement things twice for the asyncio
>> world and the classic world. To me, it would be important to use one
>> function in either world where it suits me better. I am uncertain if that
>> makes sense but right now it does to me.
>
> Yes, you cannot call async function from synchronous code. There are
> two worlds: classic and async.
My point is: why does everyone assume that it has to be like that?
@Nick
Thanks for these links; nice reads and reflect exactly what I think
about these topics. Btw. complex numbers basically works the same way
(same API) as integers. I would like to see that for functions and
awaitables as well.
Still, the general assumption is: "the sync/async split is inherent in
the problem domain". Why? I do not see that inherent split.
@Greg
I do not like wrappers IF it is just because to have wrappers. We
already have 2 types of wrappers: [normal function call] and [function
call using await]. Both works like wrappers right in the place where you
need them.
@Steven
> Where would the function suspend
> if there are zero suspension points?
It would not.
> How can you tell what the suspension
> points *in* the coroutine are from "await func()"?
Let me answer this with a question: How can you tell what the suspension
points *in* the coroutine are from "async def"?
> Can you show a code snippet of your proposal?
By analogy to PEP 0492:
def complex_calc(a):
if a >= 0:
return await open(unicode(a)).read()
l = await complex_calc(a - 1)
r = complex_calc(a - 2)
return l + '; ' + r
def business():
return complex_calc(5)
def business_new()
return await complex_calc(10)
Maybe, I completely missed the point of the proposal, but this is the
way I would expect it to work. Putting in an 'await' whenever I see fit
and it just works.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150626/75a560e2/attachment.html>
More information about the Python-Dev
mailing list