Skip to content

Add asyncio event loop support - #4071

Merged
Tryneus merged 14 commits into
rethinkdb:nextfrom
takluyver:asyncio
Apr 20, 2015
Merged

Tryneus merged 14 commits into
rethinkdb:nextfrom
takluyver:asyncio

Conversation

@takluyver

Copy link
Copy Markdown
Contributor

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):

import asyncio
import rethinkdb as r

r.set_loop_type("asyncio")

@asyncio.coroutine
def print_changes():
    conn = yield from r.connect(host="localhost", port=28015)
    feed = yield from r.table("tv_shows").changes().run(conn)
    while (yield from feed.fetch_next()):
        change = yield from feed.next()
        print(change)

loop = asyncio.get_event_loop()
loop.run_until_complete(print_changes())

@danielmewes

Copy link
Copy Markdown
Member

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/

@danielmewes danielmewes added this to the 2.1-polish milestone Apr 16, 2015
Comment thread drivers/python/rethinkdb/net_asyncio.py Outdated

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

@Tryneus

Tryneus commented Apr 16, 2015

Copy link
Copy Markdown
Member

@takluyver, thanks for putting this up, it looks great, although I made a few comments/suggestions.

@takluyver

Copy link
Copy Markdown
Contributor Author

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. ;-)

@danielmewes

Copy link
Copy Markdown
Member

Good to know about the shirts @takluyver :)

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

@takluyver

Copy link
Copy Markdown
Contributor Author

Tests are now uncommented and passing, and I think I've addressed all of the review comments so far.

@Tryneus

Tryneus commented Apr 20, 2015

Copy link
Copy Markdown
Member

Awesome, looks great, @takluyver! Merging this into next, it should make it into the 2.1 release. I'll try to get more tests in for the alternate net.py implementations before then.

Thanks for all the help!

Tryneus added a commit that referenced this pull request Apr 20, 2015
Add asyncio event loop support
@Tryneus
Tryneus merged commit 5c6a4e9 into rethinkdb:next Apr 20, 2015
@takluyver

Copy link
Copy Markdown
Contributor Author

You're welcome :-)

@takluyver
takluyver deleted the asyncio branch April 20, 2015 19:00
@danielmewes danielmewes modified the milestones: 2.2-polish, 2.1 May 7, 2015
totalwindupflightsystems pushed a commit to totalwindupflightsystems/rethinkdb that referenced this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants