Skip to content

Memory leak: warnings module #97557

@teplyakoff

Description

@teplyakoff

Bug report

Memory leak in warnings module
Steps to reproduce:

  1. Create test script
    `$ cat > memory_leak_warnings.py << EOF
    import warnings
    import random

while True:
warn_text = str(random.random())
warnings.warn(warn_text, DeprecationWarning)
EOF`

  1. Run script
    docker run -it --rm --name memory-leak-warnings -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3.9 python memory_leak_warnings.py

  2. Monitor memory usage of container with running script
    $ docker stats memory-leak-warnings

And you can see MEM USAGE constantly increased
Screenshot from 2022-09-26 10-48-45

https://docs.python.org/3/library/warnings.html
Warnings is a standard module, anyone can use it.
Having an application with a lot of dependencies - you have no idea which module use warnings module, so in production you will have memory leak.
For example aiomysql use it https://github.com/aio-libs/aiomysql/blob/master/aiomysql/cursors.py#L479 and seems like it is ok to use warnings standard module.

I have to disable warnings to get rid such kind of memory leaks. Is it ok? Or maybe warnings must be disabled on production enviroments? If so - this should be noticed in documentaion.

Thanks

Your environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions