Release the Python import lock from a thread you do not control & do not have access to
Question: So, I'm injecting a DLL into a Cython application in order to extend its
functionality. I am doing this using the following code: Note: using Python
2.7; uses the old ModuleNoBlock scheme

    
    
    PyGILState_STATE sMain = PyGILState_Ensure();
    PyObject* mHook = PyImport_ImportModuleNoBlock("hookmodule");
    PyGILState_Release(sMain);
    

Now, when I inject the DLL into the application and print errors, I get the
following:

    
    
    ImportError: Failed to import hookmodule because the import lockis held by another thread. 
    

I found the source to the imp module here:
<http://svn.python.org/projects/python/trunk/Python/import.c>

However _PyImport_ReleaseLock(void) only releases the lock if you call it from
the same thread where the lock was acquired.

Is it possible to do this?


Answer: Fixed. Use _PyImport_ReInitLock(void) before importing

