[issue12196] add pipe2() to the os module

Charles-François Natali report at bugs.python.org
Fri May 27 18:34:42 CEST 2011


Charles-François Natali <neologix at free.fr> added the comment:

> +# A constant likely larger than the underlying OS pipe buffer size.
> +# Windows limit seems to be around 512B, and most Unix kernels have a 64K pipe
> +# buffer size: take 1MB to be sure.
> +PIPE_MAX_SIZE = 1024 * 1024
>
> Hum, I am not sure that the comment is correct. If I understood correctly the usage of this constant: write PIPE_MAX_SIZE into a blocking pipe must block because PIPE_MAX_SIZE is greater than the size of the pipe buffer.

Correct.

> I don't know what happen if you write PIPE_MAX_SIZE into a nonblocking pipe: the beginning of the buffer is written and write() returns something lesser than PIPE_MAX_SIZE?
>

Correct. Note that it could also fail with EAGAIN, that's why I added
an except OSError clause to the write.

> You may specify that if you should greater or equal to os.fpathconf(fd, "PC_PIPE_BUF").
>

I don't understand what you mean. It will be greater than PIPE_BUF,
which is around 4096 (I think 512 guaranteed by POSIX).

> Here you use PIPE_MAX_SIZE*3, not PIPE_MAX_SIZE :-) You can use b'abc' * (support.PIPE_MAX_SIZE // 3), or b'a' * support.PIPE_MAX_SIZE.
>

I know, but that's what the original code did, so I kept it.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12196>
_______________________________________


More information about the Python-bugs-list mailing list