Skip to content

Python driver: auto reconnect options? #275

Open
@coffenbacher

Description

@coffenbacher

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions