Skip to content

Commit

Permalink
docs: notebook to test interupt
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Oct 3, 2023
1 parent e49cf13 commit e2ae3dc
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions examples/interrupt.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "84f0e379-e564-40db-871c-a8aca4dde3ad",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<iframe id=\"trame_trame__template_main\" src=\"http://localhost:52212/index.html?ui=main&reconnect=auto\" style=\"border: none; width: 100%; height: 100px;\"></iframe>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import asyncio\n",
"from trame.app import get_server\n",
"from trame.ui.html import DivLayout\n",
"\n",
"server = get_server(client_type=\"vue3\")\n",
"server.state.count = 1\n",
"\n",
"@server.controller.add_task(\"on_server_ready\")\n",
"async def bg(**kwargs):\n",
" while True:\n",
" with server.state as state:\n",
" state.count += 1\n",
" await asyncio.sleep(1)\n",
" \n",
"\n",
"with DivLayout(server, height=\"100px\") as layout:\n",
" layout.root.add_child(\"Hello world {{ count }}\")\n",
"\n",
"await layout.ready\n",
"layout"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "2383b286-65fc-4d96-8772-cf1b9bc62ca8",
"metadata": {},
"outputs": [
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[2], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[0;32m----> 2\u001b[0m a \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"while True:\n",
" a = 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fed1d40e-63e7-48ca-b535-e80953e29d10",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.18"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit e2ae3dc

Please sign in to comment.