[python-win32] Re: how to load 2 python COM DLLs in single app?

Thomas Heller theller at python.net
Fri Oct 22 19:18:14 CEST 2004


Niki Spahiev <niki at vintech.bg> writes:

> Thomas Heller wrote:
>
>> If you would like to work on a patch, it seems that the
>> init_with_instance() function in start.c needs to be changed, depending
>> on whether Python is already initialized or not.
>> But this may open a can of worms.
>> The only really clean way to do it would be to let py2exe create
>> single-file com servers, which even don't rely on a separate python.dll.
>
> But there are more DLL and PYD files needed to do the work. They all
> need python23.dll.

Of course.

Back to the original problem (using several frozen dll com servers in a
single process), I envision these solutions, in increasing order of
difficulty:

1. Patch py2exe's code so that sys.path is not replaced but extended
when Python is already initialized.  This gives no isolation between the
com dlls (and the main process, if it also uses Python) at all.

2. Run the com dll servers in different interpreters, with
Py_NewInterpreter(). According to the python docs, extension modules
are still shared - this may be good, or may be bad.

3. Create completely standalone, single file dlls, with no external
python.dll needed.

3a. The 'official' way to achive this is to make a static python build -
in other words: recompile python itself plus all extension modules into
a single executable (dll).  This is easy, if you use ctypes to implement
your com server.  It will be more difficult if you use pywin32, as it is
imo not yet ready to be compiled as builtin modules.

py2exe may be changed to help with this, as soon as it's possible: it
can create a config.c file listing the extension modules initxxx
functions, compile it and link it together with the rest.  The 'rest' in
this case can be Python, plus all the extensions, as static link
libraries.

3b. A hacky way may be this: It would be possible imo to create an PE
file parser/editor, which takes some dlls, reads the PE headers, import
tables, and whatever it needs and builds a new executable by combining
the code segments and creating new import tables.  I don't know if
that's really possible...

Thomas



More information about the Python-win32 mailing list