google app engine - Executing python code in parallel with ndb tasklets -
google app engine - Executing python code in parallel with ndb tasklets -
first of know can utilize threading accomplish such task, so:
import queue import threading # called each thread def do_stuff(q, arg): result = heavy_operation(arg) q.put(result) operations = range(1, 10) q = queue.queue() op in operations: t = threading.thread(target=do_stuff, args = (q,op)) t.daemon = true t.start() s = q.get() print s
however, in google app engine there's called ndb tasklets , according documentation can execute code in parallel using them.
tasklets way write concurrently running functions without threads; tasklets executed event loop , can suspend blocking i/o or other operation using yield statement. notion of blocking operation abstracted future class, tasklet may yield rpc in order wait rpc complete.
is possible accomplish illustration threading above?
i know how handle retrieving entities using get_async() (got examples @ doc page) unclear me when comes parallel code execution.
thanks.
the reply depended on heavy_operation
is. if heavy_operation
utilize rpc (remote procedure call, such datastore access, urlfetch, ... etc), reply yes.
in how understand appengine ndb.tasklet? asked similar question, may find more details there.
may set kind of code within function , decorate ndb.tasklet? used async function later. or must appengine rpc?
the answer
technically yes, not run asynchronously. when decorate non-yielding function @tasklet, future's value computed , set when phone call function. is, runs through entire function when phone call it. if want accomplish asynchronous operation, must yield on asynchronous work. in gae work way downwards rpc call.
python google-app-engine tasklet
Comments
Post a Comment