Answer the question
In order to leave comments, you need to log in
How to start executing multiple Futures at the same time?
I am writing a backend on tornado, there is a blocking function
class Recognition:
_thread_pool = ThreadPoolExecutor(max_workers=cpu_count())
...
@run_on_executor(executor="_thread_pool")
def blocking_func(self, n):
# code
return result
@gen.coroutine
def get_res(self):
a = [1, 2, 4, 7, 9...] # 13 элементов
result = yield map(self.blocking_func, a)
raise gen.Return(activations)
r = yield self.get_res()
Answer the question
In order to leave comments, you need to log in
In general, it's not about Future, but about GIL. The blocking function was CPU dependent, so the ThreadPool didn't help. I solved the problem through multiprocessing.Pool, apply_async and gen.Task.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question