New GitHub issue #118944 from sylvainmouquet:<br>
<hr>
<pre>
# Bug report
### Bug description:
```python
import asyncio
import contextvars
async def gen():
var = contextvars.ContextVar('one')
token = var.set(1)
ctx = contextvars.copy_context()
print(list(ctx.items()))
try:
yield 1
yield 2
finally:
ctx = contextvars.copy_context()
print(list(ctx.items()))
try:
var.reset(token)
except Exception as e:
print(e.args)
async def main():
async for i in gen():
print(i)
break
asyncio.run(main())
```
result :
```
[(<ContextVar name='one' at 0x107312930>, 1)]
1
[(<ContextVar name='one' at 0x107312930>, 1)]
("<Token var=<ContextVar name='one' at 0x107312930> at 0x107303480> was created in a different Context",)
```
In finally block it's not possible to manually reset the contextvars
### CPython versions tested on:
3.12
### Operating systems tested on:
macOS
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/118944">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>