You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importsysimporttriofromjinja2importTemplate, select_autoescapeclassMyModel:
classobjects:
@staticmethodasyncdefall():
whileTrue:
yield"hello"template="""<html> <head></head> <body> {% for m in model.objects.all() %} {{ m }} {% break %} {% endfor %} </body></html>"""asyncdefamain():
returnawaitTemplate(
source=template, enable_async=True, extensions=["jinja2.ext.loopcontrols"]
).render_async(model=MyModel)
defmain():
trio.run(amain)
if__name__=="__main__":
sys.exit(main())
this results in:
python -Wall demo_jinja_asyncgens.py
<template>:19: ResourceWarning: Async generator 'jinja2.async_utils.auto_aiter' was garbage collected before it had been exhausted. Surround its use in 'async with aclosing(...):' to ensure that it gets cleaned up as soon as you're done using it.
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/home/graingert/.virtualenvs/demo-jinja-asyncgens/lib/python3.12/site-packages/trio/_core/_asyncgens.py:204: ResourceWarning: Async generator '__main__.MyModel.objects.all' was garbage collected before it had been exhausted. Surround its use in 'async with aclosing(...):' to ensure that it gets cleaned up as soon as you're done using it.
await agen.aclose()
ResourceWarning: Enable tracemalloc to get the object allocation traceback
but there's no way to wrap generators with async with aclosing(...): in jinja2
Environment:
Python version: 3.12.2
Jinja version: 3.1.3
The text was updated successfully, but these errors were encountered:
given:
this results in:
but there's no way to wrap generators with
async with aclosing(...):
in jinja2Environment:
The text was updated successfully, but these errors were encountered: