def client_proc(computation, njobs, task=None):
# schedule computation with the scheduler; scheduler accepts one computation
# at a time, so if scheduler is shared, the computation is queued until it
# is done with already scheduled computations
if (yield computation.schedule()):
raise Exception('Could not schedule computation')
# send 5 requests to remote process (compute_task)
def send_requests(rtask, task=None):
# first send this local task (to whom rtask sends result)
rtask.send(task)
for i in range(5):
# even if recipient doesn't use "yield" (such as executing long-run
# computation, or thread-blocking function such as 'time.sleep' as
# in this case), the message is accepted by another scheduler
# (netpycos.Pycos) at the receiver and put in recipient's message
# queue
rtask.send(random.uniform(10, 20))
# assume delay in input availability
yield task.sleep(random.uniform(2, 5))
# end of input is indicated with None
rtask.send(None)
result = yield task.receive() # get result
print(' %s computed result: %.4f' % (rtask.location, result))
for i in range(njobs):
rtask = yield computation.run(compute_task)
if isinstance(rtask, pycos.Task):
print(' job %d processed by %s' % (i, rtask.location))
pycos.Task(send_requests, rtask)
yield computation.close()
评论列表
文章目录