Skip to content

Commit

Permalink
Add example notebook about concurrency, allow to install different fl…
Browse files Browse the repository at this point in the history
…avors of akernel (#43)
  • Loading branch information
davidbrochart committed Jul 13, 2023
1 parent bcfdb76 commit 5e0e68f
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 2 deletions.
5 changes: 4 additions & 1 deletion akernel/akernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ def install(
):
name = "akernel"
if mode:
modes = mode.split("-")
modes.sort()
mode = "-".join(modes)
name += f"-{mode}"
display_name = f"Python 3 ({name})"
write_kernelspec("akernel", mode, display_name, cache_dir)
write_kernelspec(name, mode, display_name, cache_dir)


@cli.command()
Expand Down
1 change: 1 addition & 0 deletions binder/postBuild
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

python -m pip install -e .
akernel install
akernel install react
127 changes: 127 additions & 0 deletions examples/concurrency.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1424909b-49ae-4f63-938c-c72cb3f84550",
"metadata": {},
"source": [
"If you execute the three following for-loops, you can see that they are executed concurrently."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97b4a9c1-6818-404d-9e4f-64569dd9351f",
"metadata": {},
"outputs": [],
"source": [
"__unchain_execution__()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "073b08dd-d004-4f94-8522-bfa1002c9694",
"metadata": {},
"outputs": [],
"source": [
"for i in range(5):\n",
" await asyncio.sleep(1)\n",
" print(f\"{i=}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1ced9a54-9d08-4cb7-bd57-e68db9b1d7fb",
"metadata": {},
"outputs": [],
"source": [
"for j in range(5):\n",
" await asyncio.sleep(1)\n",
" print(f\"{j=}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "98e994bb-caa2-45f7-b35d-a183facb1b72",
"metadata": {},
"outputs": [],
"source": [
"for k in range(5):\n",
" await asyncio.sleep(1)\n",
" print(f\"{k=}\")"
]
},
{
"cell_type": "markdown",
"id": "558b8d22-d221-4ea8-bc25-e261ea491b7d",
"metadata": {},
"source": [
"Now if you execute the three following for-loops, you can see that they are executed one after the other."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "422c2851-f7c8-460c-9544-13c9c8ebfe0b",
"metadata": {},
"outputs": [],
"source": [
"__chain_execution__()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21b5428c-9fcf-4150-af59-635deab42833",
"metadata": {},
"outputs": [],
"source": [
"for i in range(5):\n",
" await asyncio.sleep(1)\n",
" print(f\"{i=}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5ee578b3-6b4d-4315-ab17-8c845d740b36",
"metadata": {},
"outputs": [],
"source": [
"for j in range(5):\n",
" await asyncio.sleep(1)\n",
" print(f\"{j=}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16f0146a-fdf8-4fbe-bf37-63b2da2fe1e0",
"metadata": {},
"outputs": [],
"source": [
"for k in range(5):\n",
" await asyncio.sleep(1)\n",
" print(f\"{k=}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (akernel)",
"language": "python",
"name": "akernel"
},
"language_info": {
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion examples/reactivity.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
"kernelspec": {
"display_name": "Python 3 (akernel-react)",
"language": "python",
"name": "akernel"
"name": "akernel-react"
},
"language_info": {
"file_extension": ".py",
Expand Down

0 comments on commit 5e0e68f

Please sign in to comment.