This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author yselivanov
Recipients Max von Tettenborn, gvanrossum, vstinner, yselivanov
Date 2016-10-06.18:50:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1475779804.7.0.87639022714.issue27972@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2016-10-06 18:50:04yselivanovsetrecipients: + yselivanov, gvanrossum, vstinner, Max von Tettenborn
2016-10-06 18:50:04yselivanovsetmessageid: <1475779804.7.0.87639022714.issue27972@psf.upfronthosting.co.za>
2016-10-06 18:50:04yselivanovlinkissue27972 messages
2016-10-06 18:50:04yselivanovcreate