question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

segfault with asyncio

See original GitHub issue

On 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
scodercommented, Mar 4, 2018

Thanks for reporting back, and for the test case.

1reaction
toriningencommented, Mar 4, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found