From ff75c59b418e60b343677bd0043977ebfdddb219 Mon Sep 17 00:00:00 2001 From: roman Date: Sun, 6 Oct 2019 17:53:12 +0300 Subject: [PATCH] [FIX]: add method to close all connections created by ServerProxy --- odooly.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/odooly.py b/odooly.py index e3e345e..55b17df 100644 --- a/odooly.py +++ b/odooly.py @@ -909,6 +909,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 @@ -960,6 +961,7 @@ def _proxy_dispatch(self, name): 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): @@ -984,6 +986,11 @@ def from_config(cls, environment, user=None, verbose=False): def __repr__(self): return "" % (self._server, self.env.db_name) + def close(self): + for conn in self.connections: + conn.__exit__() + return True + def _login(self, user, password=None, database=None): """Switch `user` and (optionally) `database`.