IronLanguages/main — pull request #237 by paweljasinski (2014-11-18 13:24:34+00:00)
Title: suppress MoveNext/CurrentValue during generator finalization

This is request for feedback. Comments, ideas, tips or any help are greatly appreciated.

I have tracked down, what I believe is problem described in https://ironpython.codeplex.com/workitem/35682. The solution below fixes pylint runs which create very similar symptoms.

Except, there are a few open things which I am not able to put at rest.
1. There are 2 test in test_generator_throw which are failing.
1.1 test_del. I don't believe this one is realistic because: taking del out of it make no different. Second, it calls gc.collect() which will is not something what I would expect in user code. It is a discrepancy between cpython and ironpython, but according to another cp (https://ironpython.codeplex.com/workitem/17255) it will be there no matter what.
1.2 test_yield_except_crazy1 - exceptions are not set as expected. Well the name says it :-)
2. I am not able to create clean test cases which reproduce the problem. Any help or ideas?
3. When running pylint, I noticed Generator.Dispose being called. I am not able to trigger it outside of pylint test. Can anybody give me idea how to make it happen?

Even with all the above points, I can still argue that calling generator body in finalizer thread is asking for trouble. If it works, it is pure luck. It is difficult to set the right set of conditions, but it's not impossible.
By reading PEP 342, section about __del__, I concluded that cpython does not give 100% guarantee either. Except in case of cpython it is more of a theoretical exercise, where in ironpython it breaks existing programs.