-
-
Notifications
You must be signed in to change notification settings - Fork 858
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
Generalized concurrency backend usage #217
Generalized concurrency backend usage #217
Conversation
We definitely need to have this before we can start implementing additional backends. Thanks for opening this @florimondmanca! |
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.
Only had one comment on the current changes.
So this is great, I've got a couple thoughts in my head right now: Can we somehow create a backend that detects the current async framework we're running in and then just use that Second Im really strongly feeling that we should package trio backend support in a contrib module and then have an extra for it. Easier for us to test and easier for users since they won't have to go track down another package to get what they need to use trio just |
@sethmlarson Agreed with all your points. Backend auto-detection is a really nice feature to add to the backlog. One thing I'm thinking about just now — I suppose the import httpx
httpx.backend = "asyncio"
👉 sniffio
I'm also more inclined towards doing this as well, also for increased control and ease of change on the backend interface. |
@sethmlarson Alright, I completed reworked this PR. The commit history is clean(er) now, so feel free to go through each commit diff. The main difference with the previous state is (This doesn't have backend auto-detection because it seems premature at this stage; we can easily add it once we have |
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.
This looks great, one tiny comment!
@sethmlarson I fixed the type hint. I also added a test for passing an ASGI app to |
Nice! I'm taking a look now. :) |
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.
One comment I had then this looks good to merge! 🎉
httpx/concurrency/asyncio.py
Outdated
for task in pending: | ||
try: | ||
# Give it a chance to finish soon | ||
await asyncio.wait_for(task, timeout=0.01) |
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.
If it actually does finish should we move the task to done
?
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.
Yup. Which made me realize we can simplify this by passing the small timeout
to the first .wait()
call instead. 👍 Edited my last commit.
No idea what's going on with our CI, it's building what looks to be the completely wrong commit and I can't get it to do anything else? Weird. |
Flake8 was reporting a NameError in a test file, and I believe that was the cause of this. (Still strange that Travis is not displaying the branch and latest commit on the build!) |
Great stuff!!! I've got some thoughts on this:
I've got other thoughts on how we might want to finesse, but I think we'd look at those as a follow on:
|
Also aware that I'm being a bit rigerous wrt. asking for a smaller footprint PR here first, with the parameterization coming afterwards. If y'all think I'm being overzealous there, then potentially happy to re-consider there. 😃 |
@tomchristie I’m in favor of small PRs as well, and you’re correct saying that test parametrizarion is very much YAGNI worthy here. We could add it along with the trio backend (although that particular PR will be >400 LOC already). I’ll look into your other suggestions soon and update this PR. :-) |
Either that or add it incrementally, so that it's nicely isolated in it's own PR. I think we're probably still undecided around if trio support should be built-in or third-party right. (Both feasible avenues to my mind) In either case the main thing right now is nailing down a decent concurrency-backend API, and making sure that we're actually using it everywhere. |
Here are my thoughts for this PR, let me know what you think:
Future PRs (in order of priority?):
Thoughts? |
I’d be okay with reworking the PR towards that, except:
This needs to stick in here IMO — assuming the goal of this PR is to make sure finalize the asyncio abstraction later (ie use backends everywhere, except in tests then). Fun fact about the stream API bit — this is actually how trio does things, ie opening a connection exposes one single stream object (instead of a reader/writer pair) that allows to send and receive data. Overall I think it would be a simpler abstraction to deal with indeed. |
Indeed, yup |
Oh yeah leave that in then! |
I think each item listed by both of you could be its own PR, and that this would be so much easier to review and discuss independantly, so I started rolling out incremental PRs, e.g. with #244. I'm closing this if that's OK. :-) |
Base for #214