[issue28864] Add devnull file-like object

2018-01-29 Thread Raymond Hettinger

Raymond Hettinger  added the comment:

Closed due to lack of interest (I still think Python would be better-off with 
this feature).

--
resolution:  -> later
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28864] Add devnull file-like object

2017-01-02 Thread Martin Panter

Martin Panter added the comment:

Example where an implementation like Serhiy’s was not good enough: 
. In that case, the lack of 
flush() method causes a subtle problem.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28864] Add devnull file-like object

2016-12-05 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Which begs the question: what's the point? As David said, `open(os.devnull)` is 
a reasonably obvious way to do it. Is there a use case that it doesn't satisfy?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28864] Add devnull file-like object

2016-12-05 Thread Christian Heimes

Christian Heimes added the comment:

It can be done with some extra effort. We have to get the st_dev and st_inode 
from os.fstat(fd), cache them together with the fd, and verify them every time 
we create a new DevNull object. That way we catch both closed fd and modified 
fd. We might have to add a lock around the check, too.

--
nosy: +christian.heimes

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28864] Add devnull file-like object

2016-12-05 Thread STINNER Victor

Changes by STINNER Victor :


--
nosy: +haypo

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28864] Add devnull file-like object

2016-12-05 Thread Josh Rosenberg

Josh Rosenberg added the comment:

Didn't pre-opened (or lazily opened) file descriptors cause headaches with 
os.urandom? I'm not sure I'd want my programming environment eating file 
descriptors "just in case", even if it might make certain tasks trivially 
faster after startup.

--
nosy: +josh.r

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28864] Add devnull file-like object

2016-12-05 Thread Raymond Hettinger

Raymond Hettinger added the comment:

I had in mind a pre-opened file like sys.stderr or sys.stdout.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28864] Add devnull file-like object

2016-12-04 Thread Martin Panter

Martin Panter added the comment:

If you only need the readable interface, use BytesIO or StringIO.

I once had an implementation like Serhiy’s, called dummywriter: 
. To fully 
implement the writable file API it should also implement writable(), and 
write() should return the size of its argument.

Implementing this without opening a real file descriptor is slightly easier to 
manage (no need to worry about closing it, and no problem sharing instances or 
creating many copies). I don’t have a strong opinion about including it in the 
builtin library though, since it is pretty easy to implement the basics 
yourself.

I doubt anyone would need a readable and writable object, i.e. open(devnull, 
"r+"). On the other hand, it is occasionally useful to know how many bytes were 
written in total, so implementing tell() etc could be useful. (Linux’s 
/dev/null doesn’t work that way though; I find it always returns zero.)

--
nosy: +martin.panter

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28864] Add devnull file-like object

2016-12-04 Thread R. David Murray

R. David Murray added the comment:

Yes, in my mind open(os.devnull) is the "obvious way" to do this.

--
nosy: +r.david.murray

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28864] Add devnull file-like object

2016-12-03 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

If you need true file object, with name, fileno() etc, you can use 
open(os.devnull, 'w'). If the simple file-like object is enough, it is just few 
lines:

class NullWriter:
def write(self, s): pass

io.StringIO() works in most cases well too.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28864] Add devnull file-like object

2016-12-03 Thread Raymond Hettinger

New submission from Raymond Hettinger:

Uses cases are the same as /dev/null:

with redirect_stderr(io.DevNull()):
some_func_using_stdout_and_stderr()

--
messages: 282314
nosy: ncoghlan, pitrou, rhettinger
priority: low
severity: normal
status: open
title: Add devnull file-like object
type: enhancement
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com