0

I am looking for a way or a library to communicate asynchronously with an object an a different process. Here is an example where I want to put Solver on different processes, but still be able to communicate with the solver very often. The important thing here is, that initialization of the Solver is very expensive, so that it can only be done once per process and should live for many solve calls.

class Solver:
    def __init__(self):
        # Initializing this object is very expensive so it should be done only once
        super_expensive_initialization(self)

    async def solve(self, task):
        # This function uses asyncio to do a lot of things in parallel that will overall 
        # use this process very well
        solution = asyncio.gather([self._highly_asyncronous_solve(task) for i in range(200)])

        return await solution


    async def _highly_asyncronous_solve(self, a):
        ...


# <<< This part is what I am looking a solution for
my_solver_proxy_a = run_in_process_and_return_proxy(lambda: Solver(config_a))
my_solver_proxyb = run_in_process_and_return_proxy(lambda: Solver(config_b))
# >>>

tasks = [task_1, task_2, ...]

schedule_tasks_in_parallel(tasks, [my_solver_proxy_a, my_solver_proxyb])

I hope you can understand what I want to achieve. multiprocessing.Manager seems similar to what I want to do, but I need non-blocking calls via the Proxy.

4

0 回答 0