88from wolframclient .evaluation .kernel .asyncsession import WolframLanguageAsyncSession
99from wolframclient .exception import WolframKernelException
1010from wolframclient .utils import six
11+ from wolframclient .utils .asyncio import run_in_loop
1112from wolframclient .utils .api import asyncio
1213from wolframclient .utils .functional import is_iterable
1314
@@ -283,7 +284,8 @@ def __len__(self):
283284 return len (self ._kernel_evaluation_loop_tasks )
284285
285286
286- def parallel_evaluate (expressions , evaluator_spec = None , max_evaluators = 4 ):
287+ @run_in_loop
288+ async def parallel_evaluate (expressions , evaluator_spec = None , max_evaluators = 4 ):
287289 """ Start a kernel pool and evaluate the expressions in parallel.
288290
289291 The pool is created with the value of `evaluator_spec`. The pool is automatically stopped when it is no longer
@@ -292,9 +294,5 @@ def parallel_evaluate(expressions, evaluator_spec=None, max_evaluators=4):
292294 Note that each evaluation should be independent and not rely on any previous one. There is no guarantee that two
293295 given expressions evaluate on the same kernel.
294296 """
295-
296- async def cor ():
297- async with WolframEvaluatorPool (evaluator_spec , poolsize = max_evaluators ) as pool :
298- return await pool .evaluate_all (expressions )
299-
300- return asyncio .run (cor ())
297+ async with WolframEvaluatorPool (evaluator_spec , poolsize = max_evaluators ) as pool :
298+ return await pool .evaluate_all (expressions )
0 commit comments