This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: subprocess.DEVNULL
Type: enhancement Stage: resolved
Components: Extension Modules Versions: Python 3.3
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: rosslagerwall Nosy List: MrJean1, OG7, georg.brandl, giampaolo.rodola, gregory.p.smith, lucaspmelo, pitrou, python-dev, rosslagerwall, santoso.wijaya, socketpair
Priority: normal Keywords: patch

Created on 2009-04-28 19:24 by MrJean1, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
5870_v1.patch rosslagerwall, 2011-01-02 05:19 Patch + test for issue review
Messages (9)
msg86761 - (view) Author: Jean Brouwers (MrJean1) Date: 2009-04-28 19:24
The subprocess module exposes the PIPE and STDOUT constants to be used 
for the stdin, stdout or stderr keyword arguments.

Often, stderr needs to be redirected to /dev/null (on posix).  It would 
nice if another constant was available for that purpose, e.g. 

Perhaps, that might be as simple as


and re-use the same, single file descriptor.
msg86771 - (view) Author: Jean Brouwers (MrJean1) Date: 2009-04-28 22:06
Typo.  That should be ..., os.O_RDWR)
msg90444 - (view) Author: Lucas Prado Melo (lucaspmelo) Date: 2009-07-12 12:21
-1 on this one.
It is not a portable decision (only *nix OSes do have /dev/null).
Also, why would we want it as a default constant? The subprocess module
would need to open /dev/null every time. Despite that, I can't see how
would someone use the redirection of errors to /dev/null through a
python script and, at the same time, make it seem not a bad practice at all.
msg90446 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-07-12 12:53
Lucas, Windows has a /dev/null-like device. I think Jean's suggestion is
reasonable, but it should be a special constant instead of creating a
file descriptor unconditionnally (that is, the file should only be open
if needed). Also, a patch should be provided (with tests :-)).
msg125030 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2011-01-02 05:19
Here is a fairly simple patch that adds the subprocess.DEVNULL constant.
msg125057 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-01-02 14:42
Hmm, we don't like these open-for-eternity file descriptors; we had such a thing for os.urandom() but removed it (see #1177468).

I'm okay with DEVNULL (or even just NULL) as a shorthand, but it should open (and close) the devnull device each time just as if a normal fd was given.
msg125058 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2011-01-02 14:50
I think if you look closely at the patch, the fd does not stay open the whole time. It is opened if necessary in _get_handles() with e.g.:

elif stdin == DEVNULL:
    p2cread = self._get_devnull()

and then closed in _execute_child() with:

if hasattr(self, '_devnull'):

which is executed from __init__(). So I don't think it stays open for eternity :-)
msg125063 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-01-02 15:53
Right, sorry then :)
msg131146 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-03-16 17:36
New changeset eaf93e156dff by Ross Lagerwall in branch 'default':
Issue #5870: Add subprocess.DEVNULL constant.
Date User Action Args
2022-04-11 14:56:48adminsetgithub: 50120
2011-03-16 17:38:53rosslagerwallsetstatus: open -> closed
assignee: gregory.p.smith -> rosslagerwall
resolution: accepted
nosy: georg.brandl, gregory.p.smith, pitrou, giampaolo.rodola, OG7, MrJean1, lucaspmelo, santoso.wijaya, rosslagerwall, socketpair, python-dev
stage: needs patch -> resolved
2011-03-16 17:36:56python-devsetnosy: + python-dev
messages: + msg131146
2011-03-05 10:17:43santoso.wijayasetnosy: + santoso.wijaya
2011-03-05 09:29:55ned.deilysetnosy: + socketpair
2011-03-05 09:28:55ned.deilylinkissue11404 superseder
2011-01-02 15:53:11georg.brandlsetassignee: gregory.p.smith

messages: + msg125063
nosy: + gregory.p.smith
2011-01-02 14:50:30rosslagerwallsetnosy: georg.brandl, pitrou, giampaolo.rodola, OG7, MrJean1, lucaspmelo, rosslagerwall
messages: + msg125058
2011-01-02 14:42:42georg.brandlsetnosy: + georg.brandl
messages: + msg125057
2011-01-02 05:19:19rosslagerwallsetfiles: + 5870_v1.patch
versions: + Python 3.3, - Python 2.7
nosy: + rosslagerwall

messages: + msg125030

keywords: + patch
2010-10-11 17:51:34giampaolo.rodolasetnosy: + giampaolo.rodola
2010-10-07 17:05:50amaury.forgeotdarcsetstage: needs patch
2009-07-12 12:53:12pitrousetnosy: + pitrou
messages: + msg90446
2009-07-12 12:21:56lucaspmelosetnosy: + lucaspmelo
messages: + msg90444
2009-07-09 09:25:26OG7setnosy: + OG7
2009-04-28 22:06:31MrJean1setmessages: + msg86771
2009-04-28 19:24:02MrJean1create