-
Notifications
You must be signed in to change notification settings - Fork 160
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
Add async finalizers to the request-context #59
Comments
Unlike what I thought, it appears that the event loop isn't running inside finalizers. That means that my task would indeed never have been executed. Consequently, this achieves what I was looking for: @pytest.fixture
def foo_fixture(request, event_loop):
def fin():
async def afin():
await some_stuff()
event_loop.run_until_complete(afin())
request.addfinalizer(fin)
return 42 I let you choose to close this issue or not. My point of view is that it would at least deserve a proper documentation. Better API would be nice to have, but since it's py35 only use-case, I don't really see the point, finally. I can submit a documentation PR for this if you will. Let me know. |
My 2c: just document it. IMO 3.6 asyncio is way better than 3.5 and we (as a community) should steer new developers to 3.6. |
@dimaqq Thanks! Can't agree more. The point is that LTS versions of some well-known Linux distros won't get support for py36 unless using third-party packages. So I'll just stick to 3.5 until next LTS. |
Hi,
My project is Python 3.5 only, and it's therefore impossible for me to use async generators in fixtures. But we might be able to workaround this if it were possible to define async finalizers to
request
.E.g.
Then it would await for each async finalizers before tear down.
Not sure whether it would involve monkey patching on the request object, or what would be acceptable. Maybe there are also more proper solutions that doesn't involve
request
or that make use of already existing features? I already tried to useloop.create_task()
in a standard finalizer, unfortunately, the created task seem to execute after teardown which produces the following error message:2017-06-26 18:15:50,262 - asyncio - ERROR - Task was destroyed but it is pending!
Many thanks!
The text was updated successfully, but these errors were encountered: