Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Is Python/C api thread safety enough?

Thread Tools

Is Python/C api thread safety enough?

Posts: n/a
i make a multi thread C/C++ program emded python, each thread running a python sub-interpreter, to make it safety i make code as following between acquire/release the globle interpreter lock:
according to the python document this will avoid to block other thread that running python code since the function will take a long time, but i am wandered if the code of func_take_a_long_time() call a Python/C api, is this conflict with other threads and cause fatal error? i have release the interpreter lock in Py_BEGIN_ALLOW_THREADS and without protected from thread conflict, so if the func_take_a_long_time() call a Python/C api, it perhaps use other thread's context to running python code.

Can sombody tell me is this possible? Thanks first.

Donnie Leen

Reply With Quote
Nick Coghlan
Posts: n/a
Casper wrote:
> Can sombody tell me is this possible? Thanks first.

If you're going to call the Python C/API, you need to be holding the GIL. So you
either can't release it, or the long-running function has to use
PyGILState_Ensure when it needs to call the Python C/API.

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining Java Reflection API with Java Annotation Types for Thread Safety pek Java 2 10-23-2007 03:00 PM
DB API and thread safety Robin Haswell Python 2 01-20-2006 01:20 PM
Re: Re: Is Python/C api thread safety enough? Donnie Leen Python 2 11-25-2004 07:04 AM
What is thread safety? Hans ASP .Net 1 10-12-2004 03:15 PM
LiteralControl thread safety. George Ter-Saakov ASP .Net 1 04-06-2004 10:06 AM