David Abrahams wrote:
Python extension module B calls shared library Q and uses Q's callback interface. Because some of the callbacks need to use the Python API, and *might* be invoked by threads, they must all acquire the GIL.
Wrong. If the code in B that calls Q does not allow threads, the callbacks don't need to reacquire the GIL.
Problem: using B while A is loaded breaks A: because B has installed callbacks in Q that acquire the GIL, A must also release the GIL before calling into Q.
Can you please explain what a callback is? Can the callbacks occur in the context of a different thread, i.e. different from the one that has installed the callback? If it is a true callback (i.e. Q will call B back while being called from B), then this won't interfere at all with A. Regards, Martin