-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Retrieve four things from the web with concurrency #938
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add a simple example to show how to create a client that gathers multiple web resources _concurrently_ . I am not sure if this example is serial or concurrent. :-( If it is serial then it would be quite helpful for readers to understand how to make it concurrent.
loop = asyncio.get_event_loop() | ||
with aiohttp.ClientSession(loop=loop) as session: | ||
coroutines = [fetch(session, url) for url in URLS] | ||
pages = [loop.run_until_complete(coroutine) for coroutine in coroutines] |
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.
Shouldn't these be aggregated with asyncio.gather
instead?
Thanks @bhuman, asyncio.gather() was the correct way to go... I had been doing [other experiments](https://github.com/cclauss/asyncio_hacks/blob/master/factorial_futures.py) to get these asynchronous execution ideas clear in my head.
Thanks @buhman Fixed above. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What do these changes do?
Add a simple example to show how to create a client that gathers multiple web resources concurrently .
Are there changes in behavior for the user?
Accelerate the learning curve for real world use of aiohttp for clients such as web crawlers, etc.
Related issue number
Checklist
Add a simple example to show how to create a client that gathers multiple web resources concurrently . It should be quite helpful for readers to understand how to use aiohttp to gather several remote resources concurrently.