Hove wrote:Searches of the python.org site and google only talk about non-blocking as though blocking is perhaps the default, but that's not what I'm seeing.
To try to clarify this, blocking I/O
is the default. There is the concept of whether a file descriptor is "ready" for read or write, which you can test with select or poll. With blocking I/O, read or write will block until the file is ready. With non-blocking I/O they will return immediately.
A pipe, fifo, socket, or a device file such as a terminal or serial port is ready for read if there is at least some data in the input buffer, and is ready for write if there is at least some space left in the output buffer. Thus blocking I/O may wait, and non-blocking I/O will not wait.
However, a regular file is always considered ready for both read and write. There is no difference between blocking and non-blocking. If you happen to be at the end of the file, you will read zero bytes. If the disk is full, writes will fail. There is no option to wait in the hope that some other process makes the file longer or frees up disk space.
A regular file is simply not suitable for streaming data from one application to another. Even if you wanted to keep all the data permanently on disk as well, you should write it to a file
and pass it through a pipe.
(There is also a potential issue that regular files are buffered in large blocks by libc, while pipes and such are normally line buffered. Despite all this it is sometimes desirable to monitor the output of a program without having to rebuild it to output to a pipe. For this a workaround is "tail -f", which tries its best to get data in real time by monitoring for changes in the file length.)
By the way, /dev/shm (tmpfs) is not backed by RAM but by virtual memory, which includes swap. Even it is swaps, though, it should be much faster than any disk-based filesystem would be, because it does not survive a reboot, so it stores no permanent metadata. Now that you have switched to a fifo, it takes up no space anyway.
Disabling swap will almost always reduce performance, because the Foundation's images are already configured to swap only as a last resort. So your application may crash because there is not enough memory, or it may be slower because the kernel cannot swap other programs out to make more room. It cannot be faster because the kernel was swapping it just for fun.