-
-
Notifications
You must be signed in to change notification settings - Fork 812
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
Proof of concept for parallel requests #52
Conversation
What about adding a bulk request, that gather tasks and await for results, I can't think of any use case (maybe because I just woke up) but I m'sure there's quite |
perhaps a join() to gather all pending results.. |
Not really sold on it. If you do that, then you need to consider how it interacts with exceptions, and what happens when multiple cases raise exceptions. The only two types of primitives we need are Once you’ve got those two, then building any wrapping behaviour around that is easy. |
have you seen this? |
So I think TaskGroup is basically trio’s nursery concept. In which case, yeah the parallel blocks already adhere to that style. |
What about having a similar API to This way, users can reuse the same code between async-awaiting one task vs many tasks. |
Just commented over on #50 (comment) , but the requests-toolbelt has methods that allows it to join responses, handle exceptions, and whatnot: https://toolbelt.readthedocs.io/en/latest/threading.html e.g. (cut-and-paste from the linked doc): from requests_toolbelt.threaded import pool
urls = [
# My list of URLs to get
]
p = pool.Pool.from_urls(urls)
p.join_all()
for response in p.responses():
print('GET {0}. Returned {1}.'.format(response.request_kwargs['url'],
response.status_code))
for exc in p.exceptions():
print('GET {0}. Raised {1}.'.format(exc.request_kwargs['url'],
exc.message))
new_pool = pool.Pool.from_exceptions(p.exceptions())
new_pool.join_all() |
Hi everyone, I guess, it might be worth prefixing the page with "this is in alpha / beta" as to not mislead the user. On that note, will this be merged soon / is there a schedule on this? --Karl. |
@inventionlabsSydney So - we've got a prominent note at the top of https://www.encode.io/http3/parallel/ I hadn't noticed that we also need one in the place that we link to it from the |
My apologies Tom I should have seen that notice!
From: Tom Christie <notifications@github.com>
Reply-To: encode/http3 <reply@reply.github.com>
Date: Wednesday, 3 July 2019 at 5:57 pm
To: encode/http3 <http3@noreply.github.com>
Cc: Karl Kloppenborg <karl@hyperconnect.com.au>, Mention <mention@noreply.github.com>
Subject: Re: [encode/http3] Proof of concept for parallel requests (#52)
@inventionlabsSydney So - we've got a prominent note at the top of https://www.encode.io/http3/parallel/
I hadn't noticed that we also need one in the place that we link to it from the AsyncClient docs.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I'd love to see this implemented, and I see it's just a wee bit out of date with master. Is there anything I can do to assist? |
I guess you could start out by issuing a new pull request that brings this up to date with master. |
Should I start with this branch, or parallel-2? |
Don't mind either way, but a new branch name might be simpler? |
Yeah, I'd start with a new branch from current master, just wanted to see if one or the other had better logic to copy over and update. I should have some time this weekend to bang something out. |
I'm not terribly versed in async/await, so here's my 2c about the non-async suggestions:
I've combined these two observations with my own implementation of parallel requests a while ago, just writing some pseudocode from memory: with Pool(8) as p:
for response in p.imap_unordered(requests.get, [site_a, site_b, site_c, ...]):
process(response) I'm not suggesting using this exact pattern, I'm just trying to influence the design to be a) more pythonic, b) more controllable in terms of traffic. |
Here's another possible API: https://github.com/python-trio/trimeter |
A while ago I have implemented essentially a pooled async client (along the lines of https://medium.com/@cgarciae/making-an-infinite-number-of-requests-with-python-aiohttp-pypeln-3a552b97dc95), and I had the idea (but not the time) that it might make sense to mimic the already familiar interface from |
Oh, I missed that big warning banner - shame, this is exactly what I'm looking for. Any idea on when it might land? |
Oh :'( |
To issue a bunch of requests together...
Alternatively, to issue requests in parallel and deal with each as if they'd been issued sequentially...
This gets more exciting if we follow through on #51 and go sync first.
(Since we'll be able to provide a standard sync interface, on top of an async parallelization backend)
Very much open to API rejigs on this one. Considerations with why it looks the way it does...
next_response
orget_response
if you want it.)