KEMBAR78
[mypyc] Free coroutine after await encounters StopIteration by JukkaL · Pull Request #19231 · python/mypy · GitHub
Skip to content

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jun 4, 2025

Previously the awaited coroutine could stay alive until the coroutine that performed the await was freed, delaying object reclamation. The reference counting analysis doesn't understand registers spilled to the environment, so we need to manually clear the value.

Consider code like this:

async def foo() -> None:
    await bar()
    await zar()

Previously, the bar() coroutine was only freed at end of foo(). Now we release it before await zar(), as expected.

Previously the awaited generator could stay alive until the generator
that performed the await was freed, delaying object reclamation. The
refcount analysis doesn't understand registers spilled to the
environment, so we need to manually clear the value.

Consider code like this:
```
async def foo() -> None:
    await bar()
    await zar()
```
Previously, the `bar()` generator was only freed at end of `foo()`. Now
we release it before `await zar()`, as expected.
@JukkaL JukkaL changed the title [mypyc] Free generator after await encounters StopIteration [mypyc] Free coroutine after await encounters StopIteration Jun 4, 2025
@JukkaL JukkaL merged commit ab61ec2 into master Jun 4, 2025
13 checks passed
@JukkaL JukkaL deleted the mypyc-async-temp-free branch June 4, 2025 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants