Skip to content

creating new greenlets appears to leak memory rapidly in python 3.11 / linux #328

Description

@zzzeek

hi there -

This is indirect from SQLAlchemy where we use greenlet for our asyncio implementation, reported in sqlalchemy/sqlalchemy#8763.

The below script creates a greenlet and calls one switch. Running on linux under any Python 3.11 version with greenlet installed from pypi (greenlet-2.0.0.post0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl), the script below grows by about 10M per second. Under Python 3.10, memory is flat at about 10 megs resident.

import greenlet
import time


def greenlet_spawn(fn, *args, **kwargs):
    context = greenlet.greenlet(fn, greenlet.getcurrent())
    result = context.switch(*args, **kwargs)
    return result



def hi():
    time.sleep(.001)
    return "hello"

def go():
    while True:
        print(greenlet_spawn(hi))
go()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions