Skip to content

Commit

Permalink
[FIX]: add method to close all connections created by ServerProxy tin…
Browse files Browse the repository at this point in the history
  • Loading branch information
arkhan committed Jan 8, 2023
1 parent 59d95ec commit cb4c1b1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions odooly.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@ class Client(object):
def __init__(
self, server, db=None, user=None, password=None, transport=None, verbose=False
):
self.connections = list()
self._set_services(server, transport, verbose)
self.env = Env(self)
if db: # Try to login
Expand Down Expand Up @@ -1067,6 +1068,7 @@ def _proxy_xmlrpc(self, name):
proxy = ServerProxy(
self._server + "/" + name, transport=self._transport, allow_none=True
)
self.connections.append(proxy)
return proxy._ServerProxy__request

def _proxy_jsonrpc(self, name):
Expand All @@ -1088,6 +1090,11 @@ def from_config(cls, environment, user=None, verbose=False):
client.login(user or conf_user, password=password, database=db)
return client

def close(self):
for conn in self.connections:
conn.__exit__()
return True

def __repr__(self):
return "<Client '%s#%s'>" % (self._server, self.env.db_name)

Expand Down

0 comments on commit cb4c1b1

Please sign in to comment.