[python-win32] Passing an object to a process

Tim Roberts timr at probo.com
Wed Mar 14 20:41:58 CET 2012


Tony Cappellini wrote:
>
> On Windows XP - I've got a program running which has spawned a process
> using os.spawnv().
>
> My program has a logger object instantiated that I want to pass to the
> process that was spawned.

That's impossible.  Objects are just memory, and memory cannot be shared
between processes.


> I need to log errors seen by the process, to the same logfile that the
> program uses for logging.

You can certainly create a new logger instance in your spawned process
and have it write to the same file.  As long as the logging module
flushes after each write, that should work.


> For legacy compatibility reasons, I'm stuck with an older version of
> Python that doesn't have the subprocess module and other features that
> are available with more modern releases of Python.

Another alternative is to use popen instead of spawn, and have your
spawned process write its messages to stdout.  You could then echo them
on to the logfile in your original process.  That has its own buffering
problems.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list