with gil

The with gil branch brings some neat features. You can now say ‘with gil:’ and have any GIL-requiring code inside that block. Exceptions are propagated through nogil code and try/finally may now be used if there is a with gil block inside the try.

Of course, if with gil is used from a cdef function from a non-Python thread, it is the user’s responsibility to call PyEval_InitThreads() beforehand, in the same way it’s needed for ‘with gil’ functions.

Whenever the user (c)imports cython.parallel, PyEval_InitThreads() is called on the user’s behalf, as only the OpenMP master thread is allowed to call PyGILState_Ensure(), but we need any OpenMP thread to be able to acquire the GIL.

About markflorisson

Blog for the Cython gsoc 2011
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s