Skip to content
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

Python driver: auto reconnect options? #275

Open
coffenbacher opened this issue Mar 13, 2017 · 1 comment
Open

Python driver: auto reconnect options? #275

coffenbacher opened this issue Mar 13, 2017 · 1 comment
Labels

Comments

@coffenbacher
Copy link

coffenbacher commented Mar 13, 2017

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
@AtnNn AtnNn added the Python label Mar 17, 2017
@4F2E4A2E
Copy link

4F2E4A2E commented Apr 6, 2020

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.

@gabor-boros gabor-boros transferred this issue from rethinkdb/rethinkdb May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants