segfault with asyncio
See original GitHub issueOn macOS 10.12.4, Cython 0.25.2, Python 3.6.1, if you await asyncio.sleep() <= Cython <= Python chain, it will segfault. It won’t die if you await Cython future right away, without first using Python.
Here is an example that reproduces this bug:
main.py:
WANT_CRASH = True
import asyncio
import cy_test
async def main():
await cy_test.say()
loop = asyncio.get_event_loop()
if WANT_CRASH:
loop.run_until_complete(main())
else:
loop.run_until_complete(cy_test.say())
loop.close()
cy_test.pyx:
import asyncio
from py_test import py_async
async def cy_async():
print("- this one is from Cython")
async def say():
await cb()
async def cb(): # renaming this to "say" would prevent crash
print("Async functions can be awaited without problem:")
await cy_async()
await py_async()
print("And this will actually sleep for 3 seconds before crashing")
await asyncio.sleep(3)
print("I will be never output, because app has crashed already")
py_test.py:
async def py_async():
print("- and this one is from Python")
Setup.py:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
setup(
name='asyncio_cb',
ext_modules=cythonize([
Extension("cy_test", ["cy_test.pyx"]),
]),
)
Makefile:
all:
python3 Setup.py build_ext --inplace
test: all
python3 main.py
clean:
@echo Cleaning
@rm -f cy_*.c *.o *.so *~ core
@rm -rf build
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Issue 38785: Segmentation fault in asyncio - Python tracker
Issue 38785: Segmentation fault in asyncio - Python tracker. This issue tracker has been migrated to GitHub, and is currently read-only. For ...
Read more >Anyone else seen this segmentation fault with asyncio ... - Twitter
it means you are programming too fast. you hit the programming speed limit aka hamming limit. Codes that attain the Hamming bound are...
Read more >Segfault while debugging async code on `except` statement
I'm using FastAPI, its test client, and have some async functions to handle API calls. When when using the debugger, I get segmentation...
Read more >Segfault when using aiohttp.ClientSession and asyncio.wait
Am I using the asyncio tools wrongly here? After trying to fix it, I replaced result = asyncio.run(coro()) with loop = asyncio.new_event_loop() ...
Read more >'[issue31061] asyncio segfault when using threadpool and "_asyncio ...
List: python-bugs-list Subject: [issue31061] asyncio segfault when using threadpool and "_asyncio" native module From: Antoine Pitrou <report () bugs ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for reporting back, and for the test case.
@scoder, I’ve bisected this bug, and it seems that commit 3cd1e3da1766246b6b2fb053e651c1a2bed382b7 is fixing it, just as you’ve said 3 weeks ago. Sorry for misleading you, I don’t know exact reason why it had reproduced at my side since then, but most realistic explanation is that I’ve forgot to clean up lingering .c file, assuming it should be rebuilt each time.
Just to be sure, I’ve double-checked commit 829d7bbef with exact same test, it does not crash.
So, bug is seemingly fixed now, thankee-sai.