multiple threads & environment

Donn Cave donn at u.washington.edu
Fri Dec 17 15:37:50 EST 1999


Quoth c.kotsokalis at noc.ntua.gr (Constantinos A. Kotsokalis):
|   a (simple?) question: If I have a python program with multiple threads
|   of execution, does each one of them start with their own os.environ
|   dictionary? What I want to do is to have an environment variable
|   different for each thread. I am using the Threading module, if that
|   is any further help, and add/change the environment variable in the
|   function that the thread executes (i.e. not passing it as an
|   argument).

I think there are two ways to look at this.  On one hand, the
environment is a region of memory in the executing image, and
the program units that refer to it do so via a global address.
So there is only one environment, however many threads there
may be.

On the other hand, it's data like any other dictionary, and
each thread can certainly maintain its own private "environment"
data.  What use is this?  Well, it depends on what you want to
do with the data.  If it's to be passed to another program the
thread will execute, then you could use the posix.execve()
function, whose last parameter is the environment - data, that is.

	Donn Cave, University Computiong Services, University of Washington
	donn at u.washington.edu



More information about the Python-list mailing list