Yury Selivanov added the comment:

This is an interesting mind twister.  The key problem is that 
`self.runner_task` is blocked on *itself*: so Task._fut_waiter is set to the 
Task.

Therefore when the task is being cancelled, `Task.cancel` simply recurses.

One way to solve this is to prohibit tasks to await on themselves.  Right now 
the following code "kind of" works:

  async def f():
    loop.call_later(1, lambda: t.set_result(42))
    return await t

  loop = asyncio.get_event_loop()
  t = loop.create_task(f())
  print(loop.run_until_complete(t))

albeit it logs errors about invalid Future state.

My proposal is to raise a ValueError if Task is asked to await on itself.

Guido, what do you think?

----------

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

Reply via email to