We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Extending Cython with GIL-free types

Formal Metadata

Title
Extending Cython with GIL-free types
Title of Series
Number of Parts
115
Author
Contributors
License
CC Attribution - NonCommercial - ShareAlike 4.0 International:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
Cython is a compiled language, largely inspired by Python, which can already provide both massive speedups and seamless interoperability with C libraries. In Cython, Python and C can freely mix thanks to a unified syntax and gradual typing. This opens the door to bypassing the GIL by restricting oneself to the C side of Cython, but it entails letting go of all the high-level semantics of Python and going back to low-level manual memory management, pointer arithmetic and good old segmentation faults... Not to mention all the joys of multi-threading in C! In this talk, we will recount how we experimentally extended Cython to bridge that gap with GIL-free reference-counted types and a type system for thread-safe concurrency. We call this extension: Cython+. By hacking a bit the Cython compiler, one can create new language features which translate under-the-hood to low-level GIL-agnostic C or C++. In this way we extended Cython with a new class system that looks familiar to a Python programmer, but can be used in Cython while the GIL is released because it does not depend on the Python/C API. By adapting the way Cython generates reference counting instructions for Python objects, we equipped our types with a thread-safe reference count. Thanks to Cython's expertise with the Python/C API, we wrapped our types into extension types, thus gaining interoperability with Python. And using Cython's static type checking, we are currently introducing an ownership type system for thread-safe concurrency inspired by Pony and Rust.