rethinkdb-python icon indicating copy to clipboard operation
rethinkdb-python copied to clipboard

Python driver: auto reconnect options?

Open coffenbacher opened this issue 8 years ago • 1 comments

Is there any better way of getting a connection object that automatically reconnects than below? Closed connections keep throwing exceptions in random places in my code. I really don't care if my connection closed itself for whatever reason, I just want queries to run, so I'm trying to implement something like this 👍

an instance patch

import types

c = r.connect()

def auto_reconnect(self):
    if self._instance is None or not self._instance.is_open():
        self.reconnect()
    
c.check_open = types.MethodType( auto_reconnect, c )

c.close()

# Succeeds
r.db('simulator').table('watch_list').count().run(c)

or a general monkey patch

from rethinkdb import Connection

def auto_reconnect(self):
    if self._instance is None or not self._instance.is_open():
        self.reconnect()

Connection.check_open = auto_reconnect

coffenbacher avatar Mar 13 '17 18:03 coffenbacher

I am also very interested in a smart reconnect way for the python rethinkdb driver. You script seems to be it, but the import does not know types or Connection.

I am using rethinkdb v2.4.5 pip package.

4F2E4A2E avatar Apr 06 '20 06:04 4F2E4A2E