-
-
Notifications
You must be signed in to change notification settings - Fork 29.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
async generator allows concurrent access via async_gen_athrow_throw and async_gen_asend_throw #117881
Comments
the problem is async_gen_athrow_throw and async_gen_asend_throw are not setting/checking |
a demo showing that this is reproducible using asyncio, as well as manual generator manipulation: import asyncio
class MyExc(Exception):
pass
async def main():
task1 = None
task2 = None
async def agenfn():
nonlocal task1
nonlocal task2
try:
yield
except asyncio.CancelledError:
pass
task1 = asyncio.current_task()
try:
await asyncio.sleep(0)
except asyncio.CancelledError:
task2 = asyncio.current_task()
raise
agen = agenfn()
await anext(agen)
try:
async with asyncio.TaskGroup() as tg:
tg.create_task(agen.athrow(MyExc))
tg.create_task(agen.athrow(MyExc))
raise MyExc
except* MyExc:
pass
if task1 is not task2:
print("task changed between yield calls!")
asyncio.run(main()) outputs:
|
I'm getting lost in this, and I guess I'm not the only one.
but I remembered have other tasks lined up before 3.13 beta 1, and I probably shouldn't go too deep in this rabbit hole right now. Do you think a map like this would help find similar bugs? Does something similar already exist? |
@graingert Does my question make sense? |
@encukou yes, I think it would be useful - where should it go? In the docs or just in a comment in genobject.c? |
A comment is fine. If it's too long, it could be a separate document referenced from genobject.c. Or possibly the devguide, if pretty rendering would be worth writing it in ReST. Not the user-facing docs though. |
Bug report
Bug description:
outputs:
should print:
CPython versions tested on:
3.8, 3.9, 3.10, 3.11, 3.12, 3.13, CPython main branch
Operating systems tested on:
Linux
see also #7468 and #74956
Linked PRs
The text was updated successfully, but these errors were encountered: