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.

classification
Title: Add a pipe type (FIFO) to the io module
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, benjamin.peterson, christian.heimes, eric.araujo, martin.panter, pitrou, serhiy.storchaka, stutzbach
Priority: normal Keywords:

Created on 2010-09-24 15:19 by pitrou, last changed 2022-04-11 14:57 by admin.

Messages (10)
msg117292 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-24 15:19
While writing tests for nntplib, it came to me that a PipeIO or BytesPipeIO would be useful (I actually wrote a minimal one). It would be a non-seekable in-memory bytes buffer with distinct read and write pointers, so as to act like a system FIFO or a socket.makefile() object. A pure Python implementation would probably be sufficient, since the main use would be for test purposes. What do you think?

(you may point to os.pipe() but it has problems such as limited buffer size: try to write many bytes to the write end and it will block until the other end tries to read something)
msg117294 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-24 15:26
> It would be a non-seekable in-memory bytes buffer with distinct 
> read and write pointers, so as to act like a system FIFO or a 
> socket.makefile() object.

What would it do when the equivalent system FIFO object would block?

> (you may point to os.pipe() but it has problems such as limited buffer
> size: try to write many bytes to the write end and it will block until
> the other end tries to read something)

In the past, I've gotten around that limitation by using threads (which, admittedly, certainly had its own drawbacks)
msg117296 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-24 15:33
> > It would be a non-seekable in-memory bytes buffer with distinct 
> > read and write pointers, so as to act like a system FIFO or a 
> > socket.makefile() object.
> 
> What would it do when the equivalent system FIFO object would block?

Simply buffer everything.
(this is more aimed at mocking sockets than system FIFOs; system FIFOs
can be trivially wrapped in a BufferedRWPair)

> > (you may point to os.pipe() but it has problems such as limited buffer
> > size: try to write many bytes to the write end and it will block until
> > the other end tries to read something)
> 
> In the past, I've gotten around that limitation by using threads
> (which, admittedly, certainly had its own drawbacks)

Sure, but that's a lot of complication in itself.
msg117297 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-09-24 15:35
The _multiprocessing module already have similar objects.
_multiprocessing.Connection is based on file descriptors (and initialized with the result of os.pipe())
_multiprocessing.PipeConnection uses Windows named pipes.
msg117298 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-24 15:36
> Simply buffer everything.

That works for when a write operation would block.  What would it do when a read operation would block?
msg117300 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-24 15:44
> > Simply buffer everything.
> 
> That works for when a write operation would block.  What would it do
> when a read operation would block?

Good question. It could either return an empty bytes object, or perhaps
raise EOFError (it could be a constructor argument).
msg117301 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-24 15:48
> The _multiprocessing module already have similar objects.
> _multiprocessing.Connection is based on file descriptors (and initialized with the result of os.pipe())
> _multiprocessing.PipeConnection uses Windows named pipes.

_multiprocessing.Connection exposes a socket-like API (recv/send) rather
than file-like (read/write/etc.).
Furthermore, _multiprocessing isn't available everywhere; and I wouldn't
really trust it in terms of stability.
msg117302 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-24 15:53
Another option would be to have the read-end act like a non-blocking socket (i.e., raise EAGAIN).

Since it would mostly be for testing, would it make more sense to add it to test.support or someplace similar instead of io?
msg117303 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-24 15:59
> Another option would be to have the read-end act like a non-blocking
> socket (i.e., raise EAGAIN).
> 
> Since it would mostly be for testing, would it make more sense to add
> it to test.support or someplace similar instead of io?

I thought it might be useful for third-party libraries, or even
non-testing situations (although obviously the latter wouldn't be very
common). But, yes, a starting point could be test.support. It would also
avoid having to write unit tests and docs :)
In this case, I would like to do it as a part of the nntplib patch.
msg117305 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-24 16:11
> I thought it might be useful for third-party libraries, or even
> non-testing situations 

That might be true, but I prefer that we give code a more vigorous exercise before putting it in the standard library proper.  When we try to use it for something more than nntplib tests we might find that we need to alter its behavior slightly or flesh out the functionality more.

> But, yes, a starting point could be test.support. It would also
> avoid having to write unit tests and docs :)

+1 from me.
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54148
2015-06-15 13:47:00serhiy.storchakasetnosy: + serhiy.storchaka
2015-06-14 23:49:45martin.pantersetnosy: + martin.panter
2013-07-07 16:14:57christian.heimessetnosy: + christian.heimes

versions: + Python 3.4, - Python 3.2
2010-10-27 12:25:45eric.araujosetnosy: + eric.araujo
2010-09-24 16:11:48stutzbachsetmessages: + msg117305
2010-09-24 15:59:36pitrousetmessages: + msg117303
2010-09-24 15:53:59stutzbachsetmessages: + msg117302
2010-09-24 15:48:03pitrousetmessages: + msg117301
2010-09-24 15:44:30pitrousetmessages: + msg117300
2010-09-24 15:36:37stutzbachsetmessages: + msg117298
2010-09-24 15:35:09amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg117297
2010-09-24 15:33:05pitrousetmessages: + msg117296
2010-09-24 15:26:29stutzbachsetmessages: + msg117294
2010-09-24 15:19:21pitroucreate