Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

aiohttp examples should use async context manager for session creation #9

Closed
asvetlov opened this issue Sep 10, 2016 · 4 comments
Closed

Comments

@asvetlov
Copy link

E.g. instead of

with aiohttp.ClientSession() as session:
    ...

Use

async with aiohttp.ClientSession() as session:
    ...

Also please be consistent: either pass loop everywhere (aiohttp.Timeout(5, loop=loop), asyncio.gather(*tasks, loop=loop)) or don't pass it at all.

For first case calling asyncio.set_event_loop(None) at very begin of the program effectively checks that loop is passed to any call where it's required.

@vstinner
Copy link
Contributor

Hi Andrew! Would you mind to send a pull request please?

@asvetlov
Copy link
Author

Sure, but the question is: do you prefer explicit loop or not?
In all my code I pass loop explicitly because I've found it as best practice for writing safe code and avoiding stupid mistakes.
On other hand it may be too complex for beginners.

@ludovic-gasc
Copy link
Collaborator

For me, ok for explicit loop, most AsyncIO libraries do that.

@vstinner
Copy link
Contributor

I shut down the project: #33

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants