Cython keywords
Okay, so how does this affect you and, more importantly, your code? It is important to know what way your code should and/or will execute in a concurrent manner. Without an understanding of this, your debugging will be confusing. There are times when the GIL gets in the way and can cause issues by blocking the execution of your C code from Python or vice versa. Cython allows us to control the GIL with the gil
and nogil
keywords, which is much simpler by wrapping this state for us:
Cython |
Python |
---|---|
With gil |
|
With nogil |
|
I find that it's easier to think of multithreading in Python in terms of blocking and nonblocking the execution. In the next example, we will examine the steps needed to embed a web server into a toy messaging server.