Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion ox_ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"""


VERSION = '0.4.0'
VERSION = '0.4.1'
14 changes: 11 additions & 3 deletions ox_ui/core/simple_rpc_client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Simple tools for making an RPC client.
"""

from collections.abc import Callable
import datetime
from logging import getLogger
import threading
import traceback
from typing import Optional
import xmlrpc.client
from xmlrpc.client import Transport

Expand Down Expand Up @@ -72,7 +74,8 @@ class SimpleRPCCall(threading.Thread):


def __init__(self, url, command_name, cmd_args, after=None,
rpc_timeout=30, daemon=True, **kwargs):
rpc_timeout=30, daemon=True,
log_func: Optional[Callable[[str], None]] = None, **kwargs):
"""Initializer.

:param url: URL of server.
Expand All @@ -89,6 +92,10 @@ def __init__(self, url, command_name, cmd_args, after=None,

:param daemon=True: Whether the thread is daemonic.

:param log_func=None: Optional callable which takes a string
log message. If None, then we use an
internal info logging call.

:param **kwargs: Passed to threading.Thread.__init__.

"""
Expand All @@ -99,6 +106,7 @@ def __init__(self, url, command_name, cmd_args, after=None,
self.cmd_args = cmd_args
self.after = after
self.result = None
self.log_func = log_func or LOGGER.info

def run(self):
"""Do RPC call, put result into self.result, and do callback.
Expand All @@ -116,8 +124,8 @@ def run(self):
self.result = method(self.cmd_args)
finish = datetime.datetime.now()
duration = finish-start
LOGGER.info('Finished %s in %s seconds', self.command_name,
duration.total_seconds())
msg = f'Did {self.command_name} in {duration.total_seconds()}'
self.log_func(msg)
except Exception: # pylint: disable=broad-except
LOGGER.exception('Problem in running command %s',
self.command_name)
Expand Down
Loading
Loading