From 08e6df4a176bb0319052b20d651f1a868c83834a Mon Sep 17 00:00:00 2001 From: Andre Merzky Date: Tue, 9 Jul 2024 23:49:55 +0200 Subject: [PATCH 1/2] allow client logging --- src/radical/utils/zmq/client.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/radical/utils/zmq/client.py b/src/radical/utils/zmq/client.py index 4ec40aab..3f5289f4 100644 --- a/src/radical/utils/zmq/client.py +++ b/src/radical/utils/zmq/client.py @@ -9,6 +9,7 @@ from ..misc import as_string from ..serialize import to_msgpack, from_msgpack from .utils import no_intr, sock_connect +from .logger import Logger # ------------------------------------------------------------------------------ @@ -24,8 +25,9 @@ class Client(object): # -------------------------------------------------------------------------- # - def __init__(self, server: str = None, - url: str = None) -> None: + def __init__(self, server: str = None, + url: str = None, + log: Logger = None) -> None: if server: self._url = read_json('%s.cfg' % server)['addr'] @@ -36,8 +38,8 @@ def __init__(self, server: str = None, else: raise ValueError('need server name/cfg or Url') + self._log = log self._cb = None - self._ctx = zmq.Context() self._sock = self._ctx.socket(zmq.REQ) @@ -61,9 +63,14 @@ def url(self) -> str: # def request(self, cmd: str, *args: Any, **kwargs: Any) -> Any: - req = to_msgpack({'cmd' : cmd, - 'args' : args, - 'kwargs': kwargs}) + msg = {'cmd' : cmd, + 'args' : args, + 'kwargs': kwargs} + + if self._log: + self._log.debug('request: %s', msg) + + req = to_msgpack(msg) no_intr(self._sock.send, req) From a859fa25ede0f383214e9b440faeb32bca145a42 Mon Sep 17 00:00:00 2001 From: Andre Merzky Date: Tue, 9 Jul 2024 23:53:05 +0200 Subject: [PATCH 2/2] import fix --- src/radical/utils/zmq/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/radical/utils/zmq/client.py b/src/radical/utils/zmq/client.py index 3f5289f4..c04ff3c5 100644 --- a/src/radical/utils/zmq/client.py +++ b/src/radical/utils/zmq/client.py @@ -8,8 +8,8 @@ from ..json_io import read_json from ..misc import as_string from ..serialize import to_msgpack, from_msgpack +from ..logger import Logger from .utils import no_intr, sock_connect -from .logger import Logger # ------------------------------------------------------------------------------