Skip to content

Memory leak in async code #223

@AFMHARoma

Description

@AFMHARoma

Hi. When was trying to replace stdlib logging with picologging, I noticed huge memory leak at python3.12 and any version of lib (0.9.4, 0.9.3, 0.8.1) regardless of Unix or Win is used

Here's the code sample to reproduce problem, memory slowly leaks from 15MB to 200MB after 2 hours running. In a more complicated code it grows much more, up to a few GBs in 10 mins

import asyncio
import logging
import sys

import picologging


picologging.basicConfig(level=picologging.INFO, stream=sys.stdout, format="%(asctime)s - %(levelname)s - %(message)s")

def get_logger(name: str) -> picologging.Logger:
    return picologging.getLogger(name)


async def one():
    log = get_logger("one")
    while True:
        log.info("one" * 100)
        await asyncio.sleep(0.1)


async def two():
    log = get_logger('two')
    while True:
        log.info("two" * 100)
        await asyncio.sleep(0.1)


async def three():
    log = get_logger("three")
    while True:
        log.info("three" * 100)
        await asyncio.sleep(0.1)


async def four():
    log = get_logger("four")
    while True:
        log.info("four" * 100)
        await asyncio.sleep(0.1)


async def main():
    await asyncio.gather(one(), two(), three(), four())


if __name__ == '__main__':
    asyncio.run(main())

Metadata

Metadata

Assignees

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