2011-10-24 2 views
1
rpcs = [] 
for url in urls: 
    rpc = urlfetch.create_rpc(deadline=5.0) 
    urlfetch.make_fetch_call(rpc, url) 
    rpcs.append(rpc) 
while len(rpcs) > 0: 
    rpc = apiproxy_stub_map.UserRPC.wait_any(rpcs) 
    res = rpc.get_result() 
    if res.status_code == 200: 
    ...... do something with result 
    rpcs.remove(rpc) 

어떻게 답장을 받았는지 확인하는 방법은 무엇입니까?비동기 요청의 RPC 개체에서 응답 URL을 얻는 방법 App Engine?

답변

1

사용 콜백 :

def handle_result(rpc, url): 
    ..... [your code goes here] 

def create_callback(rpc, url): 
    return lambda: handle_result(rpc, url) 

rpcs = [] 
for url in urls: 
    rpc = urlfetch.create_rpc(deadline=5.0) 
    rpc.callback = create_callback(rpc, url) 
    urlfetch.make_fetch_call(rpc, url) 
    rpcs.append(rpc) 

while rpcs: 
    rpc = apiproxy_stub_map.UserRPC.wait_any(rpcs) 
    rpcs.remove(rpc)