Bug 523851 - Error message from "subprocess" on shutdown when running instances of Popen are deleted
Summary: Error message from "subprocess" on shutdown when running instances of Popen a...
Keywords:
Status: CLOSED DEFERRED
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: python
Version: 5.4
Hardware: All
OS: Linux
low
medium
Target Milestone: rc
: ---
Assignee: Dave Malcolm
QA Contact: BaseOS QE
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-09-16 20:45 UTC by Dave Malcolm
Modified: 2012-06-14 01:21 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-06-14 01:21:46 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Dave Malcolm 2009-09-16 20:45:08 UTC
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):
python-2.4.3-27.el5

How reproducible:
100%

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"
  
Actual results:
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

Expected results:
No error message on stderr

Additional info:
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.

Comment 1 Dave Malcolm 2009-09-16 21:10:37 UTC
The workaround I'm using is to add explicit cleanup of the Popen instance to the module in question using an "atexit" handler:

def cleanup():
    global p
    del p
import atexit
atexit.register(cleanup)


Note You need to log in before you can comment on or make changes to this bug.