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

[FIX]: add method to close all connections created by ServerProxy #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions odooly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -984,6 +986,11 @@ def from_config(cls, environment, user=None, verbose=False):
def __repr__(self):
return "<Client '%s#%s'>" % (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`.

Expand Down