From 1aafb3b1f4d646092377801d857b44be5f833e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 3 Oct 2008 13:23:15 +0200 Subject: [PATCH] Add a non blocking rpc execute and use it for request_set --- tryton/gui/main.py | 11 +++++++++-- tryton/rpc.py | 12 ++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tryton/gui/main.py b/tryton/gui/main.py index 6b00040452..800a74962b 100644 --- a/tryton/gui/main.py +++ b/tryton/gui/main.py @@ -326,8 +326,15 @@ class Main(object): def request_set(self, exception=False): try: - ids, ids2 = rpc.execute('object', 'execute', - 'res.request', 'request_get') + if not exception: + res = rpc.execute('object', 'execute', + 'res.request', 'request_get') + if not res: + return ([], []) + ids1, ids2 = res + else: + ids, ids2 = rpc.execute('object', 'execute', + 'res.request', 'request_get') if len(ids): if len(ids) == 1: message = _('%s request') % len(ids) diff --git a/tryton/rpc.py b/tryton/rpc.py index c71fdf8951..f37e9ef56d 100644 --- a/tryton/rpc.py +++ b/tryton/rpc.py @@ -150,7 +150,7 @@ def context_reload(): except: pass -def execute(obj, method, *args): +def _execute(blocking, obj, method, *args): global _SOCK, _DATABASE, _USER, _SESSION if not _SOCK or not _SOCK.connected: raise Exception('NotLogged') @@ -161,7 +161,9 @@ def execute(obj, method, *args): if key in _VIEW_CACHE and _VIEW_CACHE[key][0]: args = args[:] args = args + (_VIEW_CACHE[key][0],) - _SEMAPHORE.acquire() + res = _SEMAPHORE.acquire(blocking) + if not res: + return try: try: _SOCK.send((obj, method, _DATABASE, _USER, _SESSION) + args) @@ -179,6 +181,12 @@ def execute(obj, method, *args): _VIEW_CACHE[key] = (result['md5'], result) return result +def execute(obj, method, *args): + return _execute(True, obj, method, *args) + +def execute_nonblocking(obj, method, *args): + return _execute(False, obj, method, *args) + class RPCProxy(object): def __init__(self, name):