[capi-sig] The same Python DLL loaded twice

Mateusz Loskot mateusz at loskot.net
Mon Oct 7 18:07:27 CEST 2013


On 7 October 2013 13:38, M.-A. Lemburg <mal at egenix.com> wrote:
> On 07.10.2013 14:31, Mateusz Loskot wrote:
>> Hi,
>>
>> I'm experiencing strange issue with the very same python32.dll being
>> loaded twice on Windows.
>>
>> I have an application which embeds Python.
>> Launching my app loads python32.dll for the first time and all seems
>> working well.
>> Next, under the embedded Python, I execute this one-liner
>> "import tkinter"
>>
>> This triggers loading of _tkinter.pyd, tk85.dll, tcl85.dll as well as
>> python32.dll for the second time.
>>
>> The duplicate python32.dll is loaded into different address space,
>> maintains its own thread state,
>> leading to crash from PyInit__tkinter, obviously.
>>
>> The problem seems to be similar to this one
>> http://stackoverflow.com/questions/2147729/dll-file-loaded-twice-with-dll-redirection-through-manifest/
>>
>> Has anyone experience similar issues?
>> Any ideas on possible reasons of duplicate loading of python32.dll?
>
> Could you check the version numbers of those two DLLs.
>
> It's possible that you're loading a Python DLL for say 3.2.1
> and one for 3.2.2.

Yes, I have checked that file name, file path and version of the Python DLL
which is loaded twice are all the same.
The two loadings refer to the very same file.

I eventually found where is the problem.
The application which embeds Python is linked with Python DLL
and it refers to Python assembly using custom manifest specified wit

#pragma comment(linker, "\"/manifestdependency:name='Python' ... )

But, _tkinter.pyd does not load Python through the manifest.
So, the application and the _tkinter.pyd link to Python DLL
as they would be two distinct assemblies.

If I remove the /manifestdependency directive from my application, rebuild it
and ensure Python DLL is present in DLL search path,
then no double loading occurs and all works well.

The side-by-side technology is a bit slippery :)

Best regards,
-- 
Mateusz  Loskot, http://mateusz.loskot.net


More information about the capi-sig mailing list