Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Could importing asyncio optional? #765

methane opened this issue Sep 6, 2017 · 3 comments · Fixed by #806

[Request] Could importing asyncio optional? #765

methane opened this issue Sep 6, 2017 · 3 comments · Fixed by #806


Copy link

methane commented Sep 6, 2017

After #731 is merged, importing jinja2 on Python 3 get dramatically faster.
For now, over 40% of import time is caused by asyncio support.

      - asyncio 36.123 [ms]
    - jinja2.asyncsupport 36.397 [ms]
    - jinja2.asyncfilters 0.297 [ms]
  - jinja2 84.312 [ms]

(See this gist for detail)

Jinja2's document says:

First you need to be aware that by default async support is disabled as enabling it will generate different template code behind the scenes which passes everything through the asyncio event loop.

But even when user doesn't use async support, jinja2.asyncsupport is imported:


Lines 74 to 82 in b73cb48

def _patch_async():
from jinja2.utils import have_async_gen
if have_async_gen:
from jinja2.asyncsupport import patch_all
del _patch_async

Would you make importing asyncio optional to improve import time of jinja2?

For example, faster import time is beneficial on GAE/Python.
And less import means less memory footprint too.

Copy link

Can we also look at exempting the Py3 only .py files from the Py2 wheel?

When I build pex's I also compile all .py files into .pycs and even tho 'async.*.py' files are not imported in Python2 I have issues due to the Py3 only source file existing in the Py2 wheel and trying to be compiled with 2.7.

I can have a go at a PR - Anyone got good ideas about how to do this?

Copy link
Contributor Author

methane commented Feb 5, 2018

Including Py3 only source in universal wheel or source package is very common.
I think pex must fix it. I don't think every package should change their package for pex.

Anyway, it's not relating to this issue.

Copy link

davidism commented Feb 5, 2018

This had been discussed multiple times. I'm on my phone, so can't link right now. Our stance is that if a build tool fails on files that won't be imported on unsupported versions, it's the build tool that needs to be fixed.

methane added a commit to methane/jinja that referenced this issue Feb 6, 2018
@davidism davidism added this to the 2.11 milestone Feb 6, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet

Successfully merging a pull request may close this issue.

3 participants