Skip to content

Commit 72317cd

Browse files
author
Dorian Birraux
committed
Use annotation on coroutine in parallele eval
1 parent aec9cde commit 72317cd

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

wolframclient/evaluation/pool.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from wolframclient.evaluation.kernel.asyncsession import WolframLanguageAsyncSession
99
from wolframclient.exception import WolframKernelException
1010
from wolframclient.utils import six
11+
from wolframclient.utils.asyncio import run_in_loop
1112
from wolframclient.utils.api import asyncio
1213
from 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

Comments
 (0)