[issue27972] Confusing error during cyclic yield

2017-03-31 Thread Donald Stufft

Changes by Donald Stufft :


--
pull_requests: +1051

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-10-10 Thread Max von Tettenborn

Max von Tettenborn added the comment:

You are very welcome, glad I could help.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-10-09 Thread Yury Selivanov

Yury Selivanov added the comment:

Thank you for reporting this! Closing the issue.

--
resolution:  -> fixed
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-10-09 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 8d877876aa89 by Yury Selivanov in branch '3.5':
Issue #27972: Prohibit Tasks to await on themselves.
https://hg.python.org/cpython/rev/8d877876aa89

New changeset 41c4f535b5c0 by Yury Selivanov in branch '3.6':
Merge 3.5 (issue #27972)
https://hg.python.org/cpython/rev/41c4f535b5c0

New changeset 47720192b318 by Yury Selivanov in branch 'default':
Merge 3.6 (issue #27972)
https://hg.python.org/cpython/rev/47720192b318

--
nosy: +python-dev

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-10-07 Thread Guido van Rossum

Guido van Rossum added the comment:

I've meditated on this and I've changed my mind. A task that awaits
itself is so obviously not following the task protocol that it should
be shot on sight. No exceptions. (Only the task itself should ever set
the result or exception, and *only* by returning or raising. So the
only way a task waiting for itself could be unblocked is through
cancellation, and there are better ways to wait forever until
cancelled.)

IOW @1st1 I think it's okay to detect this and raise an exception.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-10-06 Thread Guido van Rossum

Guido van Rossum added the comment:

Maybe it could be fixed rather than making this a checked failure?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-10-06 Thread Yury Selivanov

Yury Selivanov added the comment:

> Is that enough? What if the recursion involves several tasks waiting
for each other in a cycle?

I'm not sure... Maybe it's OK when two tasks await on each other, I think the 
current Task implementation should be able to handle that.  The problem with 
the Task awaiting itself is that the current implementation just crashes with a 
RecursionError.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-10-06 Thread Yury Selivanov

Yury Selivanov added the comment:

> It's pretty perverse. But how would you detect this case?

In Task._step, we can check if the future the task is about to await on is 
"self".

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-10-06 Thread Guido van Rossum

Guido van Rossum added the comment:

Is that enough? What if the recursion involves several tasks waiting
for each other in a cycle?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-10-06 Thread Guido van Rossum

Guido van Rossum added the comment:

It's pretty perverse. But how would you detect this case? Does it
require changes to CPython or only to asyncio? Does it require a spec
change anywhere?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-10-06 Thread Yury Selivanov

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-09-06 Thread Guido van Rossum

Guido van Rossum added the comment:

Thanks for the report. I've never seen this before, so I doubt it is a
common mistake. Yury have you ever seen this?

--Guido (mobile)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27972] Confusing error during cyclic yield

2016-09-06 Thread Max von Tettenborn

New submission from Max von Tettenborn:

Below code reproduces the problem. The resulting error is a RecursionError and 
it is very hard to trace that to the cause of the problem, which is the runner 
task and the stop task yielding from each other, forming a deadlock.

I think, an easy to make mistake like that should raise a clearer exception. 
And maybe I am mistaken, but it should in principle be possible for the event 
loop to detect a cyclic yield, right?


import asyncio


class A:
@asyncio.coroutine
def start(self):
self.runner_task = asyncio.ensure_future(self.runner())

@asyncio.coroutine
def stop(self):
self.runner_task.cancel()
yield from self.runner_task

@asyncio.coroutine
def runner(self):
try:
while True:
yield from asyncio.sleep(5)
except asyncio.CancelledError:
yield from self.stop()
return


def do_test():
@asyncio.coroutine
def f():
a = A()
yield from a.start()
yield from asyncio.sleep(1)
yield from a.stop()

asyncio.get_event_loop().run_until_complete(f())

--
components: asyncio
messages: 274547
nosy: Max von Tettenborn, gvanrossum, haypo, yselivanov
priority: normal
severity: normal
status: open
title: Confusing error during cyclic yield
type: behavior
versions: Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com