Why you might want to use extensions

It's not easy to say when it is a reasonable decision to write extensions in C/C++. The general rule of thumb could be, never, unless you have no other choice. But this is a very subjective statement that leaves a lot of room for interpretation of what is not doable in Python. In fact, it is hard to find a thing that cannot be done using pure Python code, but there are some problems where extensions may be especially useful:

  • Bypassing GIL (Global Interpreter Lock) in the Python threading model
  • Improving performance in critical code sections
  • Integrating third-party dynamic libraries
  • Integrating source code written in different languages
  • Creating custom datatypes

For example, the core language constraints such as GIL ...

Get Expert Python Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.