-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a test for `background` cells in interactive execution. It also solves some issues with `autoawait` cells.
- Loading branch information
1 parent
94c5b5d
commit 68ca288
Showing
3 changed files
with
134 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "17332601", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import aiohttp\n", | ||
"import aiohttp.web\n", | ||
"import asyncio" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4f45ca1f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"async def handle(request):\n", | ||
" name = request.match_info.get(\"name\", \"Anonymous\")\n", | ||
" text = f\"Hello, {name}\"\n", | ||
" return aiohttp.web.Response(text=text)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "9649c2ef", | ||
"metadata": { | ||
"workflow": { | ||
"step": { | ||
"autoin": true, | ||
"background": true, | ||
"in": [], | ||
"out": [] | ||
}, | ||
"version": "v1.0" | ||
} | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"event = asyncio.Event()\n", | ||
"\n", | ||
"\n", | ||
"async def stop(request):\n", | ||
" event.set()\n", | ||
"\n", | ||
"\n", | ||
"app = aiohttp.web.Application()\n", | ||
"app.add_routes(\n", | ||
" [\n", | ||
" aiohttp.web.get(\"/\", handle),\n", | ||
" aiohttp.web.get(\"/stop\", stop),\n", | ||
" aiohttp.web.get(\"/{name}\", handle),\n", | ||
" ]\n", | ||
")\n", | ||
"\n", | ||
"runner = aiohttp.web.AppRunner(app)\n", | ||
"await runner.setup()\n", | ||
"site = aiohttp.web.TCPSite(runner, \"localhost\", 43210)\n", | ||
"await site.start()\n", | ||
"\n", | ||
"_ = await event.wait()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "a293b211", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"async def client():\n", | ||
" async with aiohttp.ClientSession() as session:\n", | ||
" async with session.get(\"http://localhost:43210/\") as response:\n", | ||
" text = await response.text()\n", | ||
" return text\n", | ||
"\n", | ||
"\n", | ||
"await client()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "fbf301c1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"async with aiohttp.ClientSession() as session:\n", | ||
" try:\n", | ||
" await session.get(\"http://localhost:43210/stop\")\n", | ||
" except aiohttp.ServerDisconnectedError:\n", | ||
" pass" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Jupyter Workflow", | ||
"language": "python", | ||
"name": "jupyter-workflow" | ||
}, | ||
"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.10.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |