Multithreading with Python and C api

后端 未结 2 1749
借酒劲吻你
借酒劲吻你 2020-12-15 10:59

I have a C++ program that uses the C api to use a Python library of mine. Both the Python library AND the C++ code are multithreaded.

In particular, one th

2条回答
  •  不知归路
    2020-12-15 11:25

    You probably do not unlock the Global Interpreter Lock when you callback from python's threading.Thread.

    Well, if you are using bare python's C API you have some documentation here, about how to release/acquire the GIL. But while using C++, I must warn you that it might broke down upon any exceptions throwing in your C++ code. See here.

    In general any of your C++ function that runs for too long should unlock GIL and lock, whenever it use the C Python API again.

提交回复
热议问题