How does python pause the delegate generator
Today, I would like to share with you how python pauses delegation generator related knowledge points, the content is detailed, the logic is clear, I believe most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.
1. The generator function contains yield from expressions.
2. Pause the delegate generator at the yield from expression, and the caller can send the data directly to the sub-generator.
3. The child generator sends the output value to the caller.
4. The interpreter throws a Stopiteration and appends the return value to the exception object.
Example
# def simple_coroutine (): print ('> start') x = yield print ('- > recived', x) # main thread sc = simple_coroutine () print (1111) # can use sc.send (None), the effect is the same as next (sc) # pre-excited print (2222) sc.send ('zhuxiao') above is all the content of the article "how python pauses the delegate generator" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.