本文整理汇总了Python中request.Request.diagnostic["remote_call_put"]方法的典型用法代码示例。如果您正苦于以下问题:Python Request.diagnostic["remote_call_put"]方法的具体用法?Python Request.diagnostic["remote_call_put"]怎么用?Python Request.diagnostic["remote_call_put"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类request.Request
的用法示例。
在下文中一共展示了Request.diagnostic["remote_call_put"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call_remotely
# 需要导入模块: from request import Request [as 别名]
# 或者: from request.Request import diagnostic["remote_call_put"] [as 别名]
def call_remotely(self, rpcdata, response=True):
from datetime import datetime
r = Request("call", rpcdata)
call_started = datetime.now()
r.diagnostic["remote_call_start"] = str(call_started)
if not response:
r.request_id = None
try:
self.rpchost.put(r, self.peer_id)
except Exception as e:
if self.rpchost:
log.debug("[call_remotely] Error in RPC operation:", e)
log.debug_traceback()
return None
puttime = str(datetime.now())
if response:
self.rpchost.wait(r, timeout=10)
call_complete = datetime.now()
call_elapsed = call_complete - call_started
r.diagnostic["remote_call_complete"] = call_complete
r.diagnostic["remote_call_put"] = puttime
callinfo = self.call_stats.setdefault(rpcdata.get('func'), {})
total = callinfo.get("total")
if total:
total += call_elapsed
else:
total = call_elapsed
callinfo["total"] = total
count = callinfo.get("count", 0) + 1
callinfo["count"] = count
callinfo["avgtime"] = total / count
if not response:
return None
elif not r.result:
print "FIXME: no result should return a deferment"
return None
status, retval = r.result
if status == RPCWrapper.METHOD_OK:
return retval
elif status == RPCWrapper.METHOD_FAILED:
raise RPCWrapper.MethodFailed(False, retval)