Description of problem:
I have python code in which a module holds a reference to an instance of subprocess.Popen
(I have a module to demangle C++ symbols, implemented by using a subprocess.Popen(['c++filt']) singleton, to avoid the startup cost of running c++filt on every symbol on demand)
Recent changes to "subprocess.py" in RHEL5 python seem to have added an error message when a python process that's imported such a module quits.
I've got this down to a minimal reproducer (see below)
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Create a 2-liner file "foo.py":
from subprocess import Popen, PIPE
p = Popen(['cat'], stdin=PIPE, stdout=PIPE)
2. run this shell command from the same directory:
python -c "import foo"
Error messages appear on stderr:
Exception exceptions.AttributeError: "'NoneType' object has no attribute 'error'" in <bound method Popen.__del__ of <subprocess.Popen object at 0xb7f02f8c>> ignored
No error message on stderr
Seems to have been introduced from python-2.4.3-26.el5 to python-2.4.3-27.el5 with the introduction of python-RHEV-2.4.x-subprocess.patch
It appears that in the new Popen.__del__ method we call poll, which has a try: except os.error, and at that point "os" is None, which leads to "except os.error" failing with the AttributeError, and thus the noise to stderr.
The workaround I'm using is to add explicit cleanup of the Popen instance to the module in question using an "atexit" handler: