本文整理汇总了Python中jsonrpclib.Server.call_method方法的典型用法代码示例。如果您正苦于以下问题:Python Server.call_method方法的具体用法?Python Server.call_method怎么用?Python Server.call_method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonrpclib.Server
的用法示例。
在下文中一共展示了Server.call_method方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QueryWorker
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import call_method [as 别名]
class QueryWorker(Worker):
"""
This class wraps the Server class model with threading functionallity, to
check the values of the variables in its reports.
"""
rpc = None
queue = None
time_lapse = None
rrd_dir = None
def __init__(self, **kwargs):
Worker.__init__(self, kwargs["id"])
self.queue = kwargs["queue"]
self.rpc = JSONRPCClient("http://%(host)s:%(port)d" % kwargs)
self.time_lapse = kwargs["time_lapse"]
self.rrd_dir = kwargs["rrd_dir"]
def get_value(self, server_id, variable):
"""
"""
if variable.query:
f = 'doquery'
kwargs = {'sql': variable.query, 'parsefunc': dict, }
else:
f = 'show_status'
kwargs = {'pattern': variable.name, }
logger.debug("Method: '%s', kwargs: %s" % (f, \
repr(kwargs)))
value = self.rpc.call_method(server_id, f, kwargs)
logger.debug("Query result: %s" % repr(value))
return value
def run(self):
while not self.queue.empty():
try:
(s, se, v) = self.queue.get_nowait() # A server-variable tuple
value = self.get_value(s.id, v)
rrd = rrdtool.RRDWrapper.get_instance(s, se, v,
self.time_lapse, self.rrd_dir)
rrd.update(value[v.name])
except Queue.Empty:
pass
except Exception:
logger.exception("Exception ocurred when processing "\
"an element:")
continue
logger.debug("Finished worker job.")