|View source on GitHub|
Wrapper class for asynchronous RPC.
google.appengine.api.apiproxy_stub_map.UserRPC( service, deadline=None, callback=None, stubmap=None )
Simplest low-level usage pattern:
rpc = UserRPC('service', [deadline], [callback]) rpc.make_call('method', request, response) . . . rpc.wait() rpc.check_success()
However, a service module normally provides a wrapper so that the typical usage pattern becomes more like this:
from google.appengine.api import service rpc = service.create_rpc([deadline], [callback]) service.make_method_call(rpc, [service-specific-args]) . . . rpc.wait() result = rpc.get_result()
service.make_method_call() function sets a service- and method-
specific hook function that is called by
rpc.get_result() with the
rpc object as its first argument, and service-specific value as its
second argument. The hook function should call
and then extract the user-level result from the
protobuffer. Additional arguments may be passed from
make_method_call() to the
get_result hook via the second argument.
wait_all(), which wait for multiple RPCs.
||The service name.|
||Optional deadline. Default depends on the implementation.|
||Optional argument-less callback function.|
||optional APIProxyStubMap instance, for dependency injection.|
Return the deadline, if set explicitly (otherwise
||Return the underlying RPC's future, if present.|
||Return the get-result hook function.|
||Return the method name.|
||Return the request protocol buffer object.|
||Return the response protocol buffer object.|
||Return the service name.|
Return the RPC state.
Possible values are attributes of apiproxy_rpc.RPC: IDLE, RUNNING, FINISHING.
||Return the user data for the hook function.|
Check for success of the RPC, possibly raising an exception.
This function should be called at least once per RPC. If
hasn't been called yet, it is called first. If the RPC caused
an exceptional condition, an exception will be raised here.
The first time
check_success() is called, the postcall hooks
Get the result of the RPC, or possibly raise an exception.
This implies a call to
check_success(). If a get-result hook was
make_call(), that hook is responsible for calling
check_success(), and the return value of the hook is returned.
check_success() is called directly and
make_call( method, request, response, get_result_hook=None, user_data=None )
Initiate a call.
||The method name.|
||The request protocol buffer.|
||The response protocol buffer.|
Optional get-result hook function. If not
Optional additional arbitrary data for the get-result
hook function. This can be accessed as
This function may only be called once per RPC object. It sends the request to the remote server, but does not wait for a response. This allows concurrent execution of the remote call and further local processing (e.g., making additional remote calls).
Before the call is initiated, the precall hooks are called.
Wait for the call to complete, and call callback if needed.
wait_all() are the only time callback
functions may be called. (However, note that
wait().) Waiting for one RPC will not cause
callbacks for other RPCs to be called. Callback functions may
Callbacks are called without arguments; if a callback needs access
to the RPC object a Python nested function (a.k.a. closure) or a
bound may be used. To facilitate this, the callback may be
assigned after the RPC object is created (but before
wait_all( rpcs )
Wait until all given RPCs are finished.
This is a thin wrapper around
wait_any() that loops until all
given RPCs have finished.
Iterable collection of
wait_any( rpcs )
Wait until an RPC is finished.
WaitCanceller can also be included in the list of RPCs as a mechanism to
cancel the wait.
Iterable collection of
- Repeatedly calling
wait_any()with the same arguments will not wait; it will immediately return, meaning it will return the same RPC until one earlier in the collection finishes. The callback, however, will only be called the first time the RPC finishes (which may be here or in the