Skip to content

Instantly share code, notes, and snippets.

@scopatz
Created January 3, 2017 09:10
Show Gist options
  • Select an option

  • Save scopatz/78d1750517af479d0b42997873ff9c4a to your computer and use it in GitHub Desktop.

Select an option

Save scopatz/78d1750517af479d0b42997873ff9c4a to your computer and use it in GitHub Desktop.
async failure in Cython
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%load_ext Cython"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%%cython\n",
"\n",
"def from_cython(f):\n",
" async def bound(*args, **kwargs):\n",
" print(\"from cython coro qualname\", bound.__qualname__)\n",
" return bound"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def from_python(f):\n",
" async def bound(*args, **kwargs):\n",
" print(\"from python coro qualname\", bound.__qualname__)\n",
" return bound"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import asyncio\n",
"import logging"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"@from_cython\n",
"async def foo():\n",
" print(\"in foo\")\n",
" \n",
"@from_python\n",
"async def bar():\n",
" print(\"in bar\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"loop = asyncio.get_event_loop()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"from python coro qualname from_python.<locals>.bound\n"
]
}
],
"source": [
"# This runs successfully\n",
"loop.run_until_complete(bar())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# This will crash\n",
"loop.run_until_complete(foo())"
]
}
],
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment