By default, sys.stdin.read() and sys.stdin.read(n) block calls. I would suggest that consuming 100% of the CPU is actually related to streaming data to your script, or some other behavior not listed here.
After looking at the help documentation for sys.stdin.read , I noticed this:
read (...)
read ([size]) β read no more than size bytes, return as a string.
If the size argument is negative or skipped, read until EOF is reached. Please note that in non-blocking mode, less data than requested can be returned even if the size parameter is not specified.
(Emphasize mine.)
This means that lock mode is the default behavior that matches my experience. It also led me to search for similar questions on SO. Voila: Non-blocking reading on .PIPE subprocess in python
Good luck in adapting!
source share