[Twisted-Python] spawnProcess and environment inheritance

Brian Warner warner at lothar.com
Tue Apr 29 15:23:53 MDT 2003


I wanted to ask what people thought about a potential change to the way
reactor.spawnProcess() sets up the child's environment variables.

The current default is to provide an empty environment to the child:
reactor.spawnProcess() has a env={} default parameter. I'm wondering if this
should be changed to env=None, which would instruct os.execvpe() to let the
child inherit the environment from the parent process.

This showed up in a recent test_process.py failure, which effectively
compared a "file not found" error message obtained with popen3() against a
similar one retrieved with reactor.spawnProcess(). The test failed when it
was run in a localized environment. popen3() inherited $LANG from the parent
(in this case, LANG was set to French), and the error message came out in one
language, whereas spawnProcess() cleared the environment, and the error came
out in English. The two didn't match, so the test harness thought
spawnProcess had somehow failed.

I've changed test_process.py to explicitly pass env=None to all child
processes, but given that Python's popen2 and os.exec library functions all
default to inheritance rather than an empty environment, I'm thinking it
might be a good idea to match them and have spawnProcess() default to
inheritance too.

pros: Less surprise factor for those used to normal unix behavior. Would
reduce the differences between programs run from the shell and those run from
inside spawnProcess.

cons: Sometimes you want to clean the environment as a security measure. The
existing behavior has been around for a while and changing it might cause
problems.

What do you all think?

The change in question, in case you'd like to try it out, would be the
following one-liner:

Index: twisted/internet/default.py
===================================================================
RCS file: /cvs/Twisted/twisted/internet/default.py,v
retrieving revision 1.72
diff -u -r1.72 default.py
--- twisted/internet/default.py	21 Apr 2003 15:32:15 -0000	1.72
+++ twisted/internet/default.py	29 Apr 2003 21:19:32 -0000
@@ -149,7 +149,7 @@
 
     # IReactorProcess
 
-    def spawnProcess(self, processProtocol, executable, args=(), env={}, path=None,
+    def spawnProcess(self, processProtocol, executable, args=(), env=None, path=None,
                      uid=None, gid=None, usePTY = 0):
         p = platform.getType()
         if p == 'posix':



thanks,
 -Brian




More information about the Twisted-Python mailing list