Skip to content

Commit

Permalink
Merge pull request #423 from radical-cybertools/fix/client_log
Browse files Browse the repository at this point in the history
Fix/client log
  • Loading branch information
andre-merzky authored Oct 25, 2024
2 parents c14278e + 926ccc4 commit 0cb6d17
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/radical/utils/zmq/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from ..json_io import read_json
from ..misc import as_string
from ..serialize import to_msgpack, from_msgpack
from .utils import no_intr, sock_connect, LOG_ENABLED
from ..logger import Logger
from .utils import no_intr, sock_connect


# ------------------------------------------------------------------------------
Expand All @@ -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']
Expand All @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit 0cb6d17

Please sign in to comment.