473,890 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

surprising behaviour of os.environ.clea r

If I call os.environ.clea r in a python program child processes still
see the deleted entries. But when I iterate over the keys like so

names = os.environ.keys
for k in names:
del os.environ[k]

then the entries are also deleted for the child processes. Where is
the difference? Is this a bug?
(Observed in Python 2.5.2)

--
Joe
Jun 27 '08 #1
7 2431
On Jun 27, 4:05*pm, "Joe P. Cool" <joe.p.c...@goo glemail.comwrot e:
If I call os.environ.clea r in a python program child processes still
see the deleted entries. But when I iterate over the keys like so

names = *os.environ.key s
for k in names:
* * del *os.environ[k]

then the entries are also deleted for the child processes. Where is
the difference? Is this a bug?
(Observed in Python 2.5.2)
This is because of how os.environ is implement with a UserDict
subclass. You should report this at bugs.python.org .
>
--
Joe
Jun 28 '08 #2
Benjamin <mu************ **@gmail.comwro te:
>
On Jun 27, 4:05*pm, "Joe P. Cool" <joe.p.c...@goo glemail.comwrot e:
>If I call os.environ.clea r in a python program child processes still
see the deleted entries. But when I iterate over the keys like so

names = *os.environ.key s
for k in names:
* * del *os.environ[k]

then the entries are also deleted for the child processes. Where is
the difference? Is this a bug?
(Observed in Python 2.5.2)

This is because of how os.environ is implement with a UserDict
subclass.
Why? I mean, I can see that it happens, but I don't understand why being a
UserDict causes this.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 28 '08 #3
On Jun 27, 4:05 pm, "Joe P. Cool" <joe.p.c...@goo glemail.comwrot e:
If I call os.environ.clea r in a python program child processes still
see the deleted entries. But when I iterate over the keys like so

names = os.environ.keys
for k in names:
del os.environ[k]

then the entries are also deleted for the child processes. Where is
the difference? Is this a bug?
(Observed in Python 2.5.2)
For one thing, the expression 'os.environ.key s' will yield a method
object (not a list, as you're probably expecting), but iterating over
a method as you did should produce an exception. If you want to get
the list of environment vars, you have to call the method, like
'os.environ.key s()'.

Also, aren't changes to environment vars supposed to be visible to
child processes anyway? Which one are you suggesting that behaves the
wrong way, 'os.environ.cle ar()' or 'del os.environ[key]'?

Jun 28 '08 #4
On 28 Jun., 08:54, s0s...@gmail.co m wrote:
For one thing, the expression 'os.environ.key s' will yield a method
object (not a list, as you're probably expecting), but iterating over
a method as you did should produce an exception. If you want to get
the list of environment vars, you have to call the method, like
'os.environ.key s()'.
You are right but it's just a typo in this message, sorry. My real
code is correct.
Also, aren't changes to environment vars supposed to be visible to
child processes anyway?
Yes. Both the clear method and the del method change os.environ.
os.environ IS the environment in a python program.

Which one are you suggesting that behaves the
wrong way, 'os.environ.cle ar()' or 'del os.environ[key]'?
The former. If a key is not in os.environ, it shouldn't exist for
child
processes.
Jun 28 '08 #5
On 28 Jun., 04:05, Benjamin <musiccomposit. ..@gmail.comwro te:
On Jun 27, 4:05 pm, "Joe P. Cool" <joe.p.c...@goo glemail.comwrot e:
This is because of how os.environ is implement with a UserDict
subclass. You should report this at bugs.python.org .
issue 3227: os.environ.clea r has no effect on child processes

--
Joe
Jun 28 '08 #6
On 28 Jun., 23:06, "Joe P. Cool" <joe.p.c...@goo glemail.comwrot e:
On 28 Jun., 04:05, Benjamin <musiccomposit. ..@gmail.comwro te:
On Jun 27, 4:05 pm, "Joe P. Cool" <joe.p.c...@goo glemail.comwrot e:
This is because of how os.environ is implement with a UserDict
subclass. You should report this at bugs.python.org .

issue 3227: os.environ.clea r has no effect on child processes.
According to Benjamin Peterson this has been fixed in the upcoming
Python 2.6.
Jun 28 '08 #7
On Jun 28, 1:23*am, Tim Roberts <t...@probo.com wrote:
Benjamin <musiccomposit. ..@gmail.comwro te:
This is because of how os.environ is implement with a UserDict
subclass.

Why? *I mean, I can see that it happens, but I don't understand why being a
UserDict causes this.
The contents of a UserDict is stored in UserDict.data. When
UserDict.clear is called, that contents is simply cleared. environ
needs to override this is to unset env variable and then update the
actual dict.
--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
Jun 29 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3850
by: Erick Bodine | last post by:
I am trying to set a new environment variable on a W2k machine with only partial success. The name("SSID") and value("ASIM") show up correctly in the registry and when I go to "System Properties"->Advanced->"Environment Variables". However, if I open a console and type 'set', "SSID" is not listed; also if I open a python shell and do os.environ the variable is not found. What am I doing wrong??? import _winreg
0
1321
by: mahongquan | last post by:
when i install moinmoin in python 2.4,windows server2000, I found it has a bug,cgiHttpServer.py set environ,but the cgi python script can not get the environ variant,such as environ,so moin donot display correct web page.
0
1356
by: jtauber | last post by:
Did something change between 2.3 and 2.4 that would affect os.environ being populated with CGI variables when using the BaseHTTPServer/CGIHTTPServer? I received a bug report from someone trying to run my wiki/blog software, Leonardo under Python 2.4 on Windows 2000. I was able to reproduce the problem under Python 2.4 on Windows XP Pro but confirmed that it worked fine under Python 2.3. Simply printing out os.environ at the point...
11
3952
by: jim.eggleston | last post by:
Windows doesn't have a HOME environment variable, but it does have HOMEDRIVE and HOMEPATH. Could Windows versions of Python automatically populate os.environ with HOME, where HOME = os.path.join(os.environ, os.environ)? If this was done, then modules such as pdb, which load resource files from HOME, would work under Windows. Alternatively, here is a patch to make pdb.py read .pdbrc under Windows.
7
1432
by: codergem | last post by:
Hello Friends Can anyone help me where exactly at what address the *p is storing the updated value ( which is 99). const int k=9; int *p=(int *)&k; cout<<"Addr of k : "<<&k<<" "<<p;
45
2973
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs to check. What I expected was that there would be minor code bloat and some speed improvement when using templates. However... I wrote a basic list container (using templates), and a list container (using virtual derived classes). I also tried...
9
3759
by: boris.smirnov | last post by:
Hi there, I have a problem with setting environment variable in my script that uses qt library. For this library I have to define a path to tell the script whre to find it. I have a script called "shrink_bs_070226" that looks like this: ********************************** import sys, re, glob, shutil import os
1
7240
by: Rahul | last post by:
Hi Everyone, I once had a look at a code having the following declaration, extern ** environ or extern char ** environ... I lost the code and i'm wondering what is the exact need of this? Does anyone have any idea on this? Thanks in advance!!!
3
3928
by: Tim Chase | last post by:
Not sure what's going on here and hoping for some insight: tim@rubbish:~$ echo $COLUMNS 129 tim@rubbish:~$ python2.5 Python 2.5.2 (r252:60911, May 28 2008, 08:35:32) on linux2 Type "help", "copyright", "credits" or "license" for more information. False
0
9975
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9812
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10799
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7154
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5832
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6032
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4655
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3263
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.