Skip to content

Potential memory leak #73

@fantamiracle

Description

@fantamiracle

If you wait for a few minutes you can see the memory bloat.

pybar3 version: 0.9.7

from pybars import Compiler, strlist
import json
import time
compiler = Compiler()
from memory_profiler import profile

@profile
def replace_vars(mystr, variables):
    def _json(this, item):
        return strlist(json.dumps(item))
    if isinstance(mystr, str):
        try:
            template = compiler.compile(mystr)
        finally:
            pass
        return template(variables, helpers={"json": _json})
    return mystr

while True:
    replace_vars("{{json event}}", 
                 {'event': {'event': 'connectivity.state.changed', 'timestamp': 1640217025.7437212, 'connectStatusOk': False}, 'request': {'httpParams': {'body': '{{json event}}', 'headers': ['User-Agent: Engine', 'Content-Type: application/json'], 'method': 'post' }}})
    time.sleep(.1)

Any thoughts for a fix to a way to get around it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions