Multithreaded code

Chances are that your application may be using multithreaded code. Python is not considered suitable for multithreaded code because of the Global Interpreter Lock (GIL). The good news is that, in Cython, you can explicitly unlock the GIL and make your code truly multithreaded. This is done by simply putting a statement with nogil: in your code. You can later acquire the GIL using with gil in your code:

with nogil: 
<The code block here> 
function_name(args) with gil:  
<function body> 

Get NumPy Essentials 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.