How are generators and coroutines implemented in CPython?

后端 未结 2 1819
耶瑟儿~
耶瑟儿~ 2020-12-07 14:01

I\'ve read that in CPython, the interpreter stack (the list of Python functions called to reach this point) is mixed with the C stack (the list of C functions that were call

2条回答
  •  时光说笑
    2020-12-07 14:47

    The yield instruction takes the current executing context as a closure, and transforms it into an own living object. This object has a __iter__ method which will continue after this yield statement.

    So the call stack gets transformed into a heap object.

提交回复
热议问题