def locate(name, location=None, timeout=None):
"""Must be used with 'yield' as 'rti = yield RTI.locate("name")'.
Returns RTI instance to registered RTI at a remote peer so its method
can be used to execute tasks at that peer.
If 'location' is given, RTI is looked up at that specific peer;
otherwise, all known peers are queried for given name.
"""
if not RTI._pycos:
RTI._pycos = Pycos.instance()
req = _NetRequest('locate_rti', kwargs={'name': name}, dst=location, timeout=timeout)
req.event = Event()
req_id = id(req)
RTI._pycos._lock.acquire()
RTI._pycos._pending_reqs[req_id] = req
RTI._pycos._lock.release()
_Peer.send_req_to(req, location)
if (yield req.event.wait(timeout)) is False:
req.reply = None
rti = req.reply
RTI._pycos._lock.acquire()
RTI._pycos._pending_reqs.pop(req_id, None)
RTI._pycos._lock.release()
raise StopIteration(rti)
评论列表
文章目录