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

use asyncio.run #1444

Merged
merged 1 commit into from May 18, 2021
Merged

use asyncio.run #1444

merged 1 commit into from May 18, 2021

Conversation

davidism
Copy link
Member

@davidism davidism commented May 18, 2021

Python 3.10 shows a deprecation warning when using asyncio.get_event_loop while not in an event loop, which is the case when running the sync render method for an async template. Use asyncio.run instead, which manages running in an event loop.

generate is no longer particularly useful when called on an async template, as calling run over and over again would create new loops and be inefficient. So it collects the entire render then yields it item by item so that it's still a generator. generate already doesn't seem particularly useful, as only very simple templates without blocks or other internal buffers will actually yield one statement at a time.

I think we should deprecate calling render and generate if the template is async. It's a blocking call in async mode, and it doesn't really make sense to render an async environment from sync code, as you'd have to manage everything manually for that to be useful. It also requires ignoring some type errors. Users should call render_async from a running loop when using an async environment.

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

@davidism davidism added the async label May 18, 2021
@davidism davidism added this to the 3.0.1 milestone May 18, 2021
@davidism davidism merged commit 77674b9 into 3.0.x May 18, 2021
@davidism davidism deleted the event-loop branch May 18, 2021 20:31
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant