Title: subprocess.Popen ResourceWarning should have activation-deactivation flags
Type: resource usage Stage:
Components: Library (Lib) Versions: Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: acue, martin.panter, pitrou, python-dev, serhiy.storchaka, vstinner
Priority: normal Keywords:

Created on 2018-03-27 10:54 by acue, last changed 2018-07-22 08:30 by martin.panter.

File name Uploaded Description Edit
python3-output.txt acue, 2018-03-27 10:54 output of warnings during unittest of command line tool by stderr
Messages (3)
msg314511 - (view) Author: Arno-Can Uestuensoez (acue) Date: 2018-03-27 10:54
The subprocess call *subprocess.Popen* in Python3.6 was added a number of resource warnings, including subprocess run-state and open files. This is a very good facility for debugging, but causes a lot of trouble for programs relying on subprocesses via the STDIO/STDERR interface. The STDIO/STDERR interfaces are very common when shell utilities are incorporated into high level Python programs.

The other issue is the unit testing of command line tools as black-box tests, these solely rely on the STDOUT and STDERR interface. I am currently finishing a subprocess test package with common code for Python2.7 and Python3.5+, so facing some trouble with IO filtering. Examples are attached.

A system call should process the common IO interfaces of the called subprocesses by default without any additional output. So a call flag and/or an environment variable should be introduced in addition, which allows the activation and deactivation of these messages.
The default should be *deactive*.
msg314513 - (view) Author: Arno-Can Uestuensoez (acue) Date: 2018-03-27 10:59
See also 
issue26741 - subprocess.Popen should emit a ResourceWarning in destructor if ...
msg322136 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2018-07-22 08:30
Can’t you use Python’s existing CLI <> and environment variable <> to control the ResourceWarning messages?

Warnings where enabled by default when using the “unittest” module in Issue 10535. There is probably a way to disable them, at least by using the “warnings” module directly. But I think ResourceWarning should stay enabled by default when running tests. As you said, the warnings help testing for bugs.
Date User Action Args
2018-07-22 08:30:40martin.pantersetmessages: + msg322136
2018-03-27 10:59:31acuesetmessages: + msg314513
2018-03-27 10:54:43acuecreate