Guido van Rossum <gu...@python.org> added the comment:

Alex, the goal here is not to replicate every Trio feature or behavior. For 
example I don't think that asyncio is likely to get level cancellation in 3.11, 
but we can certainly see if we can do something about some of the edge cases 
you mention, like the case of a task that is cancelled before it has started 
running, where you say that the task should be allowed to run until its first 
await.

It would be nice to have a native asyncio example that demonstrates this, so we 
have a concrete goal.

I am thinking it is something like this:

async def send_from_open_file(f, s):
    data = f.read()
    f.close()
    await s.send(data)

async def send_filename(filename, s):
    f = open(filename)
    t = asyncio.create_task(send_from_open_file(f, s))
    t.cancel()
    await asyncio.sleep(1)

This is an interesting edge case and I can see why you'd rather see this run 
until the `await s.send(data)` line. The question is, can we do that without 
breaking other promises implicit or explicit? (Just because the docs don't 
mention some behavior that doesn't mean we can change it. We have to consider 
what happens to actual real world code.)

I don't even know if this would be easy to change if we decided it was a good 
change. Thoughts? (Possibly this discussion belongs in a new issue, since it's 
not directly related to adding cancel scopes.)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46771>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to