{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import logging\n", "logging.basicConfig(level=logging.INFO)\n", "logging.getLogger('funcx.sdk.asynchronous.polling_task').setLevel(logging.DEBUG)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Asynchronous FuncX Example\n", "This example creates an asynchronous FuncX Client and shows up to receive results" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Public tutorial endpoint: 4b116d3c-1703-4f8f-9f6f-39921e5864df\n", "tutorial_endpoint = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'\n", "\n", "from funcx.sdk.client import FuncXClient\n", "fxc = FuncXClient(funcx_service_address='http://localhost:5000/api/v1', asynchronous=True)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def sum1(nums):\n", " import time\n", " time.sleep(10)\n", " return sum(nums)\n", "\n", "func_id = fxc.register_function(sum1)\n", "func_id\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "task = fxc.run([1, 2, 3, 45, 66], function_id=func_id, endpoint_id=tutorial_endpoint)\n", "task\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import asyncio\n", "await task\n", "print(task.result())\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def boom(l):\n", " return l/0\n", "\n", "func_id2 = fxc.register_function(boom)\n", "func_id2\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "task2 = fxc.run([1, 2, 3, 45, 66], function_id=func_id2, endpoint_id=tutorial_endpoint)\n", "await task2\n", "print(task2.result())\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }