Is Python/C api thread safety enough?

Casper Kingdom.Lin at yeah.net
Sat Nov 20 04:44:04 EST 2004


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:
		Py_BEGIN_ALLOW_THREADS
		func_take_a_long_time()
		Py_END_ALLOW_THREADS
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






More information about the Python-list mailing list