async def process(self, analyses, experiment, trackers, sequences): if not isinstance(analyses, collections.Iterable): analyses = [analyses] futures = [] for analysis in analyses: futures.append(wrap_future(analysis.commit(experiment, trackers, sequences))) await wait(futures) if len(futures) == 1: return futures[0].result() else: return (future.result() for future in futures)
def handle_sign_up(req_msg_body): req = msg_packet_data_pb2.sign_up_req() req.ParseFromString(req_msg_body) ack = msg_packet_data_pb2.sign_up_ack() ack.err_code = msg_error_pb2.err_server_unknown ack.auth_token = '' print(1) yield from wrap_future(g.THREAD_POOL.submit(put_user, req)) print(2) ack.err_code = msg_error_pb2.err_none ack.auth_token = AESCrypto.generate_auth_token(req.user_id, []) return msg.pack(msg_type_data_pb2.t_sign_up_ack, ack)
def handle_create_character(req_msg_body): req = msg_packet_data_pb2.create_character_req() req.ParseFromString(req_msg_body) ack = msg_packet_data_pb2.create_character_ack() ack.err_code = msg_error_pb2.err_server_unknown ack.auth_token = '' user_id = AESCrypto.get_user_id(req.auth_token) print(1) char_names = yield from wrap_future(g.THREAD_POOL.submit(put_character, req, user_id)) print(2) ack.err_code = msg_error_pb2.err_none ack.auth_token = AESCrypto.generate_auth_token(user_id, char_names) return msg.pack(msg_type_data_pb2.t_sign_up_ack, ack)
def run_in_thread(fn, *args, **kwargs): return futures.wrap_future( thread_executor.submit(fn, *args, **kwargs), loop=get_ioloop() )
async def mapper(value: int) -> rx.AsyncObservable[int]: fut = executor.submit(long_running, value) return rx.of_async(wrap_future(fut))
def dispatch(callback: Callable[..., T], *args, **kwargs) -> Awaitable[T]: return wrap_future(pool.submit(callback, *args, **kwargs))
async def mapper(value) -> AsyncObservable: fut = executor.submit(long_running, value) return AsyncObservable.unit(wrap_future(fut))
def run_in_executor(self, func, *args): """runs given function in another thread. """ return futures.wrap_future(self.executor.submit( functools.partial(func, *args)), loop=self.ioloop.asyncio_loop)