Writing a Python extension in Go (Golang)

前端 未结 4 1665
一整个雨季
一整个雨季 2020-12-12 20:58

I currently use Cython to link C and Python, and get speedup in slow bits of python code. However, I\'d like to use goroutines to implement a really slow (and very paralleli

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-12 21:27

    I've written an extension to setuptools which allows you to write cpython extensions that interface with go: https://github.com/asottile/setuptools-golang

    There's a couple example extensions here:

    • https://github.com/asottile/setuptools-golang-examples
    • https://github.com/asottile/dockerfile

    The neat thing is these can be installed just like any other pip package and support both cpython and pypy.

    PEP 513 manylinux1 wheels can also be built to provide pre-built wheels via the setuptools-golang-build-manylinux-wheels tool.

    The approach is nearly identical to the one in @ColonelPanic's answer but uses some additional tricks to enable python2 + python3 compatibility.

提交回复
热议问题