async def main(): async with WolframEvaluatorPool() as pool: start = time.perf_counter() tasks = [pool.evaluate('Pause[1]') for i in range(10)] await asyncio.wait(tasks) print('Done after %.02fs, using up to %i kernels.' % (time.perf_counter() - start, len(pool)))
def setUpClass(cls): cls.pool = WolframEvaluatorPool( cls.KERNEL_PATH, kernel_loglevel=logging.INFO, STARTUP_TIMEOUT=5, TERMINATE_TIMEOUT=3, ) LOOP.run_until_complete(cls.pool.start())
async def test_pool_from_one_kernel(self): await self.pool.terminate() session = WolframLanguageAsyncSession(kernel_path) async with WolframEvaluatorPool(session, kernel_loglevel=logging.INFO, STARTUP_TIMEOUT=5, TERMINATE_TIMEOUT=3) as pool: await self._pool_evaluation_check(pool) self.assertFalse(session.started) self.assertTrue(session.stopped)
async def test_pool_from_one_cloud(self): session = WolframCloudAsyncSession( credentials=secured_authentication_key, server=server) async with WolframEvaluatorPool(session, kernel_loglevel=logging.INFO, STARTUP_TIMEOUT=5, TERMINATE_TIMEOUT=3) as pool: await self._pool_evaluation_check(pool) self.assertFalse(session.started) self.assertTrue(session.stopped)
def create_session(path=None, poolsize=1, inputform_string_evaluation=False, **opts): if poolsize <= 1: return WolframLanguageAsyncSession( path, inputform_string_evaluation=inputform_string_evaluation, **opts) return WolframEvaluatorPool( path, poolsize=poolsize, inputform_string_evaluation=inputform_string_evaluation, **opts)
async def runasync(): log('running runasync') async with WolframEvaluatorPool() as pool: countr = Counter(a=1) async def logAfter(wlexp, c, total): await pool.evaluate(wlexp) log(f'Finished making {c["a"]}/{total} figures') c['a'] += 1 tasks = [] for exp in wolfram_expressions2: # for exp in wolfram_expressions: tasks += [logAfter(exp, countr, len(figDats))] await asyncio.wait(tasks)
async def test_pool_from_mixed_kernel_cloud_path(self): await self.pool.terminate() sessions = (WolframCloudAsyncSession( credentials=secured_authentication_key, server=server), WolframLanguageAsyncSession(self.KERNEL_PATH), self.KERNEL_PATH) async with WolframEvaluatorPool(sessions, kernel_loglevel=logging.INFO, STARTUP_TIMEOUT=5, TERMINATE_TIMEOUT=3) as pool: await self._pool_evaluation_check(pool) for session in sessions: if not isinstance(session, six.string_types): self.assertFalse(session.started) self.assertTrue(session.stopped)
def create_session(path=None, poolsize=1, inputform_string_evaluation=False, kernel_loglevel=logging.INFO, **opts): if poolsize <= 1: return WolframLanguageAsyncSession( path, inputform_string_evaluation=inputform_string_evaluation, kernel_loglevel=kernel_loglevel, **opts) return WolframEvaluatorPool( path, poolsize=poolsize, inputform_string_evaluation=inputform_string_evaluation, kernel_loglevel=kernel_loglevel, **opts)
from __future__ import absolute_import, print_function, unicode_literals from aiohttp import web from wolframclient.evaluation import WolframEvaluatorPool from wolframclient.language import wl from wolframwebengine.web import aiohttp_wl_view session = WolframEvaluatorPool(poolsize=4) routes = web.RouteTableDef() @routes.get("/") async def hello(request): return web.Response(text="Hello from aiohttp") @routes.get("/form") @aiohttp_wl_view(session) async def form_view(request): return wl.FormFunction({"x": "String"}, wl.Identity, AppearanceRules={"Title": "Hello from WL!"}) @routes.get("/api") @aiohttp_wl_view(session) async def api_view(request): return wl.APIFunction({"x": "String"}, wl.Identity)