On Mon, Oct 31, 2011 at 4:54 PM, Greg Ewing email@example.com wrote:
Or maybe there's a third way:
- Recognise that, today, some people *are* using generators
to do coroutine-like programming and finding it a useful technique, despite all of its limitations, and consider ways to make it easier, even if we can't remove all of those limitations.
It seems to me that the inability to suspend from within a special method is not likely to be a problem very often in practice.
Doing blocking I/O in special methods (other than __next__) is generally a dubious practice anyway, so you're right that disallowing suspension when such a function is on the stack is unlikely to be a major problem.
Inability to use generators as generators in a coroutine environment may be more serious, since it's quite likely people will want to e.g. use a for-loop to iterate over lines being read from a socket, and suspend while waiting for data to arrive.
I think that particular problem could be solved, given some more thought. The question is, would it be worth the effort?
Yes, I think that one needs to be solved. The issue of providing coroutine-friendly iterative builtins and itertools functionality also need to be addressed.