def _get_results(FetcherClass, services, kwargs, num_results=None, fast=<NUM_LIT:0>, verbose=False, timeout=None):
results = []<EOL>if not num_results or fast:<EOL><INDENT>num_results = len(services)<EOL><DEDENT>with futures.ThreadPoolExecutor(max_workers=len(services)) as executor:<EOL><INDENT>fetches = {}<EOL>for service in services[:num_results]:<EOL><INDENT>tail = [x for x in services if x is not service]<EOL>random.shuffle(tail)<EOL>srv = FetcherClass(services=[service] + tail, verbose=verbose, timeout=timeout)<EOL>fetches[executor.submit(srv.action, **kwargs)] = srv<EOL><DEDENT>if fast == <NUM_LIT:1>:<EOL><INDENT>raise NotImplementedError<EOL>to_iterate, still_going = futures.wait(fetches, return_when=futures.FIRST_COMPLETED)<EOL>for x in still_going:<EOL><INDENT>try:<EOL><INDENT>x.result(timeout=<NUM_LIT>)<EOL><DEDENT>except futures._base.TimeoutError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>elif fast > <NUM_LIT:1>:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>to_iterate = futures.as_completed(fetches)<EOL><DEDENT>for future in to_iterate:<EOL><INDENT>service = fetches[future]<EOL>results.append([service, future.result()])<EOL><DEDENT><DEDENT>return results<EOL>
Does the fetching in multiple threads of needed. Used by paranoid and fast mode.