Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Deallocation of active generators causes error messages in Stackless 3.x #190

Closed
@akruis

Description

@akruis

The following small test program emits unexpected error messages:

#
# -*- coding: utf-8 -*-
#
from __future__ import print_function, absolute_import, division

import stackless
import sys
import gc

if "hard" in sys.argv:
    stackless.enable_softswitch(False)

def gen():
    try:
        stackless.schedule_remove()
        yield 1
    except:
        print("Exception in gen:", sys.exc_info(), file=sys.stderr)
        raise

def task(generator):
    for i in generator:
        pass

t = stackless.tasklet(task)(gen())
stackless.run()
assert t.paused
print("Tasklet t is paused, going to delete t", file=sys.stderr)
# must not throw or output any error messages
t = None
gc.collect()
print("gc.collect() done", file=sys.stderr)

If you call it with Stackless 3.6 and soft-switching enabled you get:

$ ./python -u Stackless/test/test_gen_gc.py 
Tasklet t is paused, going to delete t
Exception ignored in: <generator object gen at 0x7fb752002960>
ValueError: generator already executing
gc.collect() done

And without soft-switching:

$ ./python -u Stackless/test/test_gen_gc.py hard
Tasklet t is paused, going to delete t
gc.collect() done
Exception in gen: (<class 'TaskletExit'>, TaskletExit(), <traceback object at 0x7fe135189288>)
gc:0: ResourceWarning: gc: 1 uncollectable objects at shutdown; use gc.set_debug(gc.DEBUG_UNCOLLECTABLE) to list them

With Stackless 2.7 the program does not output anything unexpected.

The observed behaviour present in Stackless 3.4 and up. Stackless 3.3 shows the hard-switching behaviour for soft switching too. This change in behaviour is obviously related to PEP 442.

Expected behaviour

If a generator is executing but it's tasklet is paused, then it is not ok to close the generator (or send anything into it) without activating its tasklet. Therefore the current behaviour is not OK. This should be fixed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions