Mailing List Archive

Embedding Python - Win32 - Request for Info/Opinions
Hi,

I've gotten Python to embed in a Win32 COM dll. (It's very simple, thanks to
everyone that worked on the PCBuild stuff). I wanted to ask a couple of
general questions because I'm curious about how I can use this in an actual
app.

What do I need to install when I put this on a target machine? I start off
with creating a Python directory. If I put my COM dll, atl.dll and the
python15.dll in this directory I can get my wrapper to register...but do I
need to set PythonPath? do I need to install common py files? Where would I
put these? Do I just mirror (in a very small way) what the Python install
does? What is commonly done by people who are using Python commercially?

If I want to use win32com stuff what else do I need to install? Again, does
it mirror the Python Windows install? I would think I grab the following
files:
In win32com directory :
__init__.pyc, olectl.pyc, storagecon.pyc, util.pyc
In client directory:
All the pyc files
In server directory:
All the pyc files
And I'd put them in a directory structure that mirrors the install under the
directory where I'll put the python dll. Is this correct?

Is the Python interpreter thread-safe? In what I've done so far I've got an
in-proc dll marked as free-threaded. I have a com object that wraps the
Python interpreter and lets me pass files or strings into the interpreter.
What I want is to instantiate this COM object from different threads and
have those threads run scripts. Is this going to work? What have people done
to achieve the same kind of functionality? That is, use Python in a server
environment and get lots of different scripts executing at the same time. Do
they launch the interpreter at the command line as a separate process?

I am going to be working over the next couple days to answer these questions
on my own but if someone already has the answers then that would help me
quite a bit.

Thank you.
--
Frank McGeough
Synchrologic,Inc. www.synchrologic.com
E-mail: fm@synchrologic.com
Embedding Python - Win32 - Request for Info/Opinions [ In reply to ]
Frank McGeough writes:
>
> I've gotten Python to embed in a Win32 COM dll. (It's very simple,
> thanks to everyone that worked on the PCBuild stuff). I wanted to
> ask a couple of general questions because I'm curious about how I
> can use this in an actual app.
>
> What do I need to install when I put this on a target machine? I
> start off with creating a Python directory. If I put my COM dll,
> atl.dll and the python15.dll in this directory I can get my wrapper
> to register...but do I need to set PythonPath? do I need to install
> common py files? Where would I put these? Do I just mirror (in a
> very small way) what the Python install does? What is commonly done
> by people who are using Python commercially?

You can take complete control by providing exceptions.py and a
site.py in the app's current directory. Use site.py to force whatever
twisted perverted setup you desire. See
http://www.mcmillan-inc.com/install.html

> If I want to use win32com stuff what else do I need to install?

The above package has something that will determine all your
dependencies, both scripts and (since you have MSVC), binary.

For COM servers, COM needs to be able to find your stuff. That used
to mean installing on the PATH somewhere, but I think build 124
of Mark's stuff fixes that.

> Is the Python interpreter thread-safe? In what I've done so far I've
> got an in-proc dll marked as free-threaded.

This should work fine. Python is thread safe for Python-created
threads. Getting it to work with C-created threads is do-able, but a
headache.

> I have a com object that
> wraps the Python interpreter and lets me pass files or strings into
> the interpreter. What I want is to instantiate this COM object from
> different threads and have those threads run scripts. Is this going
> to work? What have people done to achieve the same kind of
> functionality? That is, use Python in a server environment and get
> lots of different scripts executing at the same time.

We've seen postings from people working towards this same idea, but
I've never been clear on why you'd run have one process executing a
bunch of independent scripts. It's a lot less work and not much more
load on the OS to run separate processes.


- Gordon
Embedding Python - Win32 - Request for Info/Opinions [ In reply to ]
"Frank McGeough" <frank.mcgeough@synchrologic.com> wrote:

> What do I need to install when I put this on a target machine? I start off
> with creating a Python directory. If I put my COM dll, atl.dll and the
> python15.dll in this directory I can get my wrapper to register...but do I
> need to set PythonPath? do I need to install common py files? Where would I
> put these? Do I just mirror (in a very small way) what the Python install
> does? What is commonly done by people who are using Python commercially?

What we do (thanks to Mark Hammond), is change PC/python_nt.rc to
create a new registry base for our python:

//#define MS_DLL_ID "1.5.1"
#define MS_DLL_ID "QuickStep"

Then we create path and module subkeys under that, all of which point
to our install directory. We then copy all of the (many) needed .pyc
files (and the .pyd, etc.) into the install directory. We don't ship
the .py files by default, but I do have another kit that adds them.

The advantage of this is that our app is independant of whatever
version of Python may also be installed on the machine. The
disadvantage is that we need our own compile of the main Python dll.
Actually, we could probably get by with just editing the official
dll's embedded resources, but that makes me queasy just thinking about
it...

Dan Pierson, Control Technology Corporation
dan@control.com
Embedding Python - Win32 - Request for Info/Opinions [ In reply to ]
Dan L. Pierson wrote in message <37218679.236666031@news.randori.com>...

>
>What we do (thanks to Mark Hammond), is change PC/python_nt.rc to
>create a new registry base for our python:
>
>//#define MS_DLL_ID "1.5.1"
>#define MS_DLL_ID "QuickStep"
>

Just a minor clarification. If you have MSVC, it is possible to change this
value _without_ recompiling Python itself. So it is possible to make this
change at the source level (as Dan mentions) and also at the binary level.

Mark.