Skip to content

Gevent and rethinkdb #5396

Closed
Closed

Description

@nickmishustin

I wrote about this problem earlier and decided that all right, but I have it again.
I have gevent and rethinkdb in django project. I try use changefeed in code bellow but It not works.

class ProjectsNamespace(BaseAuthNamespace):
    def DB_listener(self):
        feed = r.table('projects').changes().run()
        for change in feed:
            self.logger.debug('changefeed event') 
    def recv_connect(self):
        self.spawn(self.DB_listener)

There are no any actions or error message. If i add gevent.sleep(0) in for body It works, but application hangs after page reload.

I tried use monkey_patch, Timeouts from gevent, native python thread and python rethinkdb driver from next but It did not help.

When I tried python driver from next somtimes I get error like it:

File "/usr/local/lib/python2.7/site-packages/rethinkdb/ast.py", line 438, in filter
return Filter(self, *[func_wrap(arg) for arg in args], **kwargs)
File "/usr/local/lib/python2.7/site-packages/rethinkdb/ast.py", line 1803, in func_wrap
if _ivar_scan(val):
File "/usr/local/lib/python2.7/site-packages/rethinkdb/ast.py", line 1793, in _ivar_scan
if any([_ivar_scan(arg) for arg in query.args]):
AttributeError: 'MakeObj' object has no attribute 'args'

Maybe anybody seen the problem early.

Activity

  1. danielmewes commented on Feb 12, 2016

    @danielmewes
    Member

    Hi @nickmishustin, we fixed the second bug yesterday in next with dd28b11 . You might want to try the latest commit.

    I'm not familiar with gevent myself. @Tryneus could you take a look at @nickmishustin example above please?
    If gevent works similar to Tornado, you might have to write something like this instead of the for loop:

    class ProjectsNamespace(BaseAuthNamespace):
        def DB_listener(self):
            feed = yield r.table('projects').changes().run()
            while (yield feed.fetch_next()):
                change = yield feed.next()
                self.logger.debug('changefeed event') 
        def recv_connect(self):
            self.spawn(self.DB_listener)
  2. Tryneus commented on Feb 13, 2016

    @Tryneus
    Member

    @nickmishustin - I do not know the details of your spawn method, or how you're using gevent in your application, so it's hard for me to tell what's causing the problem. If it helps, here is a small script that works fine for me for the same use case:

    import rethinkdb as r
    import gevent
    
    r.set_loop_type('gevent')
    
    conn = r.connect()
    feed = r.table('test').changes().run(conn)
    
    def read_feed():
      for change in feed:
        print('Change: %s' % str(change))
    
    gevent.Greenlet.spawn(read_feed).get()

    You shouldn't need to monkey-patch anything (although it shouldn't break anything, either), as the rethinkdb driver will use gevent.socket directly rather than the base socket implementation.

  3. nickmishustin commented on Feb 15, 2016

    @nickmishustin
    Author

    @danielmewes, thanks, dd28b11 fixed error above.
    @Tryneus, thanks, it works!

  4. added this to the invalid milestone on Feb 15, 2016
  5. danielmewes commented on Feb 15, 2016

    @danielmewes
    Member

    Closing since it's now working.
    Reminded me that we need to document the gevent integration though: rethinkdb/docs#1019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions