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/client log #423

Merged
merged 15 commits into from
Oct 25, 2024
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
Loading