def client_proc(computation, njobs, coro=None): # use RemoteCoroScheduler to start coroutines at servers (should be done # before scheduling computation) rcoro_scheduler = RemoteCoroScheduler(computation) # execute n jobs (coroutines) and get their results. Number of jobs created # can be more than number of server processes available; the scheduler will # use as many processes as necessary/available, running one job at a server # process # arguments must correspond to arguments for computaiton; multiple arguments # (as in this case) can be given as tuples args = [(i, random.uniform(2, 5)) for i in range(njobs)] results = yield rcoro_scheduler.map_results(compute, args) # Coroutines may not be executed in the order of given list of args, but # results would be in the same order of given list of args for result in results: print(' result for %d from %s: %s' % result)
def client_proc(computation, coro=None): # Use RemoteCoroScheduler to run at most one coroutine at a server process # This should be created before scheduling computation rcoro_scheduler = RemoteCoroScheduler(computation) # execute 10 jobs (coroutines) and get their results. Note that number of # jobs created can be more than number of server processes available; the # scheduler will use as many processes as necessary/available, running one # job at a server process algorithms = ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'] args = [(algorithms[i % len(algorithms)], random.uniform(1, 3)) for i in range(20)] results = yield rcoro_scheduler.map_results(compute, args) for i, result in enumerate(results): if isinstance(result, tuple) and len(result) == 2: print(' %ssum: %s' % (result[0], result[1])) else: print(' rcoro failed for %s: %s' % (args[i][0], str(result))) yield rcoro_scheduler.finish(close=True)