Throwing exceptions from inside coroutines.

Idea... Exceptions should be thrown out of coroutines rather than raised inside them and allowed to propagate out. There are several benefits. * It doesn't stop or leave the coroutine in a state that can't be continued. * It maintains the boundary between coroutines and other code in such a way that they may be replaced or wrapped in threads or processes easier. * It creates a new way to communicate to outside framework which simplifies creating schedulers. * It would work with yield-from expressions to almost completely eliminate any support framework like trampolines runners. (and the cothread.py module here.) My fist thoughts on this was to allow a resumable exception type, but after thinking about it more, I don't think it would be a good idea. Rather than try to explain this in words, here is a version of Nicks example cothread.py module with a throws() function that can be used to throw out an exception in a clean way. This isn't meant to be included in the library, but is a way to experiment with the API used to write coroutines as Nick suggested. Also here are two modules from Gregs examples that shows some context in which these features are used. Cheers, Ron
participants (1)
-
Ron Adam