-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
gh-125862: Context decorator support for generators and async functions #136212
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
base: main
Are you sure you want to change the base?
Conversation
|
Ack. WASI tests are failing because I used asyncio. Gotta work around that. |
Lib/contextlib.py
Outdated
| with self._recreate_cm(): | ||
| yield from func(*args, **kwds) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| with self._recreate_cm(): | |
| yield from func(*args, **kwds) | |
| with self._recreate_cm(), closing(func(*args, **kwds)) as gen: | |
| yield from gen |
I think we should be using with closing() and async with aclosing() in these wrappers, to ensure that any resources held by the wrapped function are cleaned up promptly. (see e.g. PEP-533 motivation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
@ambv I recall that back in July in Prague you said you'd take a look at this PR, yes? Would now be a good time? |
contextlib.ContextDecoratorsupport for generators and async functions #125862