Skip to content

Commit 838780f

Browse files
author
Dorian Birraux
committed
Simplify parallel evaluate code.
1 parent 4c90e86 commit 838780f

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

wolframclient/evaluation/pool.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import itertools
44
import logging
55
from asyncio import CancelledError
6+
from wolframclient.utils.asyncio import get_event_loop
67

78
from wolframclient.evaluation.base import WolframAsyncEvaluator
89
from wolframclient.evaluation.kernel.asyncsession import WolframLanguageAsyncSession
@@ -291,12 +292,8 @@ def parallel_evaluate(expressions, evaluator_spec=None, max_evaluators=4, loop=N
291292
Note that each evaluation should be independent and not rely on any previous one. There is no guarantee that two
292293
given expressions evaluate on the same kernel.
293294
"""
294-
loop = loop or asyncio.get_event_loop()
295-
pool = None
296-
try:
297-
pool = WolframEvaluatorPool(evaluator_spec, poolsize=max_evaluators, loop=loop)
298-
loop.run_until_complete(pool.start())
299-
return pool.evaluate_all(expressions)
300-
finally:
301-
if pool:
302-
loop.run_until_complete(pool.terminate())
295+
async def cor():
296+
async with WolframEvaluatorPool(evaluator_spec, poolsize=max_evaluators) as pool:
297+
return await pool.evaluate_all(expressions)
298+
299+
return get_event_loop(loop).run_until_complete(cor())

0 commit comments

Comments
 (0)