[Python-Dev] Re: [PyWX] RE: PyWX (Python AOLserver plugin)

Michael Haggerty mhagger@alum.mit.edu
Wed, 13 Sep 2000 01:08:57 -0400 (EDT)


Brent Fulgham writes:
> Titus -- any chance s/UNIX/pthreads/ ?  I.e., would using something
> like AOLserver's threading libraries help by providing more
> thread-local storage in which to squirrel away various environment
> data, dictionaries, etc.?

The problem isn't a lack of thread-local storage.  The problem is that
*everything* in unix assumes a single environment and a single PWD.
Of course we could emulate a complete unix-like virtual machine within
every thread :-)

> Idea:  If Python forks a subshell, it inherits the parent
> process's environment.  That's probably the only time we really want
> to let someone modify the os.environ -- so it can be passed to
> a child.

Let's set os.environ to a normal dict (i.e., break the connection to
the process's actual environment) initialized to the contents of the
environment.  This fake environment can be passed to a child using
execve.  We would have to override os.system() and its cousins to use
execve with this fake environment.

We only need to figure out:

1. Whether we can just assign a dict to os.environ (and
   posix.environ?) to kill their special behaviors;

2. Whether such changes can be made separately in each interpreter
   without them affecting one another;

3. Whether special measures have to be taken to cause the fake
   environment dictionary to be garbage collected when the interpreter
   is destroyed.

Regarding PWD there's nothing we can realistically do except document
this limitation and clobber os.chdir() as suggested by Guido.

Michael

--
Michael Haggerty
mhagger@alum.mit.edu