[issue34701] Asyncio documentation for recursive coroutines is lacking

2018-09-15 Thread Azaria Zornberg


Azaria Zornberg  added the comment:

Ah, thanks for the clarification!

I first encountered this when having some issues with converting large objects 
to json. json.dumps happens synchronously, and when executed on an object that 
was dozens of MB in size, it held up everything for a fair bit of time.
I tried to solve it by recursively running json.dumps on smaller pieces of the 
thing being converted to json. And that was when I realized that this still 
wasn't letting other things get scheduled.

When I looked for examples online, I didn't see any of a recursive asyncio 
coroutine, which is why I assumed the recursion was the issue.


Any advice on better ways to phrase the documentation are greatly appreciated! 
Alternatively, it sounds like you have a much better understanding of this than 
I do, so I'm happy to defer to whatever you believe is the correct way to 
document this. Thanks for the help!

--

___
Python tracker 
<https://bugs.python.org/issue34701>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34701] Asyncio documentation for recursive coroutines is lacking

2018-09-15 Thread Azaria Zornberg


Change by Azaria Zornberg :


--
keywords: +patch
pull_requests: +8762
stage:  -> patch review

___
Python tracker 
<https://bugs.python.org/issue34701>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34701] Asyncio documentation for recursive coroutines is lacking

2018-09-15 Thread Azaria Zornberg


New submission from Azaria Zornberg :

When an asynchronous coroutine in asyncio awaits or yields from itself, any 
call to the function is executed somewhat synchronously.

Once the recursive coroutine begins, if it never awaits any other coroutines 
besides itself, nothing else will be scheduled to run until it has completely 
finished recursively calling itself and returning.
However, if it ever awaits a different coroutine (even something as small as 
asyncio.sleep(0)) then other coroutines will be scheduled to run.

It seems, from other documentation, that this is intentional. Other 
documentation sort of dances around the specifics of how coroutines work with 
recursion, and only examples of coroutines yielding from each other recursively 
are provided.

However, this behavior is never explicitly called out. This is confusing for 
people who write a recursive asyncio coroutine and are perplexed by why it 
seems to execute synchronously, assuming they ever notice.

I've attached a short script that can be run to exhibit the behavior.
A PR is going to be filed shortly against the python 3.7 branch (as the 
documentation page for asyncio in 3.8 does not fully exist right now).

--
assignee: docs@python
components: Documentation, asyncio
files: asyncio_await_from_self_example.py
messages: 325468
nosy: asvetlov, azaria.zornberg, docs@python, yselivanov
priority: normal
severity: normal
status: open
title: Asyncio documentation for recursive coroutines is lacking
type: enhancement
versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7
Added file: https://bugs.python.org/file47805/asyncio_await_from_self_example.py

___
Python tracker 
<https://bugs.python.org/issue34701>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com