Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Finally block of generator is not executed during garbage collection #828
In Python, when a generator object is garbage collected, its finally block will be executed and any print statement in it will be displayed on console.
Consider the python file
When it is executed in command line, the output will be:
Similar output is obtained when the code is defined in python 3 interactive shell:
The print statement in finally block is executed when the program ends/ the interactive shell exits.
However, when the same program is executed in voc, the finally block is not executed even though a
(the finalize method invokes next() on the generator to resume execution, so it should execute the print statement in the generator when garbage collector invokes the finalize method)