[issue43736] asyncio create_task() odd behavior

Yanghao Hua report at bugs.python.org
Tue Apr 6 04:05:49 EDT 2021


Yanghao Hua <yanghao.py at gmail.com> added the comment:

This unfortunately contradicts to all the other concurrency semantics
I know, I have myself implemented various event-driven schedulers and
none of them would behave like this.

Consider an OS as the simplest example, you have a main thread that
starts many child threads, there shouldn't be a single case (not even
a possibility) that starting a child thread would block the main
thread.

And coming back to this particular example, semantically equivalent
code, producing completely different behavior for me is a major bug.
The correct way to implement "await a_task" should be like
"process().run()", rather than waiting for completion. After all,
"await t0" did *NOT* wait until t0's completion! but if you wrote
"await create_task()" it does wait ...! seems not right to me.

I strongly ask for a second opinion before we close this bug ...

On Mon, Apr 5, 2021 at 11:23 PM Zachary Ware <report at bugs.python.org> wrote:
>
>
> Zachary Ware <zachary.ware at gmail.com> added the comment:
>
> You missed something :)
>
> By immediately awaiting the result of `create_task`, you're synchronizing thing.  It's the same as just rearranging the lines of the first example to:
>
> t0 = create_task(task("T0", 10))
> print("starting tasks ...")
> await t0
> t1 = create_task(task("T1", 10))
> await t1
>
> Basically, `t1` simply doesn't exist yet when you ask `t0` to run to completion.
>
> ----------
> nosy: +zach.ware
> resolution:  -> not a bug
> status: open -> pending
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <https://bugs.python.org/issue43736>
> _______________________________________

----------
status: pending -> open

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43736>
_______________________________________


More information about the Python-bugs-list mailing list