[Python-Dev] is this a bug? no environment variables

Guido van Rossum guido at python.org
Mon Nov 22 17:33:57 CET 2010


On Sun, Nov 21, 2010 at 9:40 PM, Glenn Linderman <v+python at g.nevcal.com> wrote:
> In reviewing my notes from my experimentations with CGIHTTPServer
> (Python2.6) and then http.server (Python 3.2a4), I note one behavior I
> haven't reported as a bug, nor do I know where to start to figure it out,
> other than experimentally.
>
> The experiment: launching CGIHTTPServer without environment variables, by
> the simple expedient of using a batch file to unset all the existing
> environment variables, and then launching Python2.6 with CGIHTTPServer.
>
> So it failed early: random.py fails at line 110 (Python 2.6).

What specific traceback do you get? In my copy of the code that line says

                a = long(_hexlify(_urandom(16)), 16)

and I could just imagine that _urandom() fails for some reason to do
with the environment (it is a reference to os.urandom()), which, being
part of the C library code, might depend on the environment.

But you're not giving enough info to debug this.

> I suppose it is possible that some environment variables are used by Python
> directly (but I can't seem to find a documented list of them) although I
> would expect that usage to be optional, with fall-back defaults when they
> don't exist.

That is certainly the idea, but the fallbacks may not always be nice.

Environment variables used by Python or the stdlib itself are supposed
to be named PYTHON<whatever> if they are Python-specific, and there's
a way to disable all of these (-E). But there are other environment
variables (HOME and PATH come to mind) that have a broader definition
and that are used in some part of the stdlib. Plus, as I mentioned,
who knows what the non-Python C library uses (well, somebody probably
knows, but I don't know of a central source that we can actually trust
across the many platforms where Python runs).

> I suppose it is even possible that some Windows APIs might
> depend on some environment variables, but I expected that the registry had
> replaced such usage completely, by now, with the environment variables
> mostly being a convenience tool for batch files, or for optional, temporary
> alteration of particular settings.

That sounds like wishful thinking. :-)

> If anyone knows of documentation listing what environment variables are
> required by Python on Windows, I would appreciate a pointer, searches and
> doc browsing having not turned it up.
>
> I'll attempt to recreate the test situation later this week with Python
> 3.2a4, if no one responds, but the only debug technique I can think of is to
> slowly remove environment variables until I find the minimum set required to
> run http.server successfully for my tests with CGI files.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list