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 asyncio event loop support #4071
Conversation
That's really cool, thanks a lot for the pull request @takluyver ! @Tryneus I think this is one for you to review. Can you take a look when you find the time? @takluyver Have you signed our CLA yet? http://rethinkdb.com/community/cla/ |
|
||
def _empty_error(self): | ||
# We do not have RqlCursorEmpty inherit from StopIteration as that interferes | ||
# with Tornado's gen.coroutine and is the equivalent of gen.Return(None). |
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 should be asyncio
, not Tornado
- and the gen.Return(None)
thing isn't quite true when using yield from
.
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.
I think the same problem would still arise - return foo
in a coroutine still works by raising StopIteration(foo)
, I believe. I'll update the comment.
@takluyver, thanks for putting this up, it looks great, although I made a few comments/suggestions. |
Thanks, I was fully expecting that it wouldn't be quite right. I'll respond to comments inline. @danielmewes I just went and signed the CLA now. The address field mentioned that you might send me something - if that's a t-shirt, then save yourselves the postage, because I already picked up two at PyCon. ;-) |
Good to know about the shirts @takluyver :) |
|
||
return (sum(cursor_counts), sum(cursor_timeouts)) | ||
|
||
# @asyncio.coroutine |
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.
Is there a reason these tests are commented out? Were they taking too long? If I remember correctly they're the longest-running tests in the suite.
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.
Oh, I was commenting out chunks of the tests just so that I could run them quickly. I didn't mean to commit them commented out.
Tests are now uncommented and passing, and I think I've addressed all of the review comments so far. |
Awesome, looks great, @takluyver! Merging this into Thanks for all the help! |
Add asyncio event loop support
You're welcome :-) |
This probably needs quite a bit of work, but it's working for a basic example, and I wanted to communicate early. @techdragon talked me into working on this at the PyCon sprints.
Asyncio is part of the standard library in Python 3.4. It's a rather similar API to tornado, so I copied and pasted the net_tornado code that's already in rethinkdb and modified it until it works. The syntax is only valid on Python 3, but the module shouldn't be imported until you do
r.set_loop_type('asyncio')
, so that shouldn't be a problem.Here's the asyncio version of the tornado example from your async drivers blog post (BTW, that example is missing a colon on the
while
line):