Commit e0c94ef2 authored by Stefan Behnel's avatar Stefan Behnel

Keep direct closure of generators and coroutines intact during cleanup by...

Keep direct closure of generators and coroutines intact during cleanup by disabling their tp_clear() as they still need their closure for handling the final GeneratorExit call.
parent 69f3183a
......@@ -2660,6 +2660,9 @@ class CreateClosureClasses(CythonTransform):
class_scope = entry.type.scope
class_scope.is_internal = True
class_scope.is_closure_class_scope = True
if node.is_async_def or node.is_generator:
# Generators need their closure intact during cleanup as they resume to handle GeneratorExit
class_scope.directives['no_gc_clear'] = True
if Options.closure_freelist_size:
class_scope.directives['freelist'] = Options.closure_freelist_size
......
# mode: run
# tag: generator
import cython
import sys
......@@ -24,6 +25,9 @@ def test_generator_frame_cycle():
eval('g.throw(ValueError)', {'g': g})
del g
if cython.compiled:
# FIXME: this should not be necessary, but I can't see how to do it...
import gc; gc.collect()
return tuple(testit)
......@@ -53,4 +57,7 @@ def test_generator_frame_cycle_with_outer_exc():
del g
assert sys.exc_info()[1] is exc, sys.exc_info()
if cython.compiled:
# FIXME: this should not be necessary, but I can't see how to do it...
import gc; gc.collect()
return tuple(testit)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment