OSSubprocess icon indicating copy to clipboard operation
OSSubprocess copied to clipboard

Do not block launched process when redirecting output

Open demarey opened this issue 5 years ago • 1 comments

When you run a process, it can write some data to the standard output (or error). Example:

p := OSSUnixSubprocess new
	command: '/bin/bash';
	arguments: #('-c' '/tmp/pharo-vm/Pharo.app/Contents/MacOS/Pharo /tmp/Pharo.image eval "[ 70 timesRepeat: [ Stdio stderr nextPutAll: (String loremIpsum: 1024). 0.01 second wait. ] ] fork"');
	run.

If you run the process without trying to read the standard error, everything is fine. Then, if you run the same process, listening to the standard error, the launched process will freeze.

p := OSSUnixSubprocess new
	command: '/bin/bash';
	arguments: #('-c' '/tmp/pharo-vm/Pharo.app/Contents/MacOS/Pharo /tmp/Pharo.image eval "[ 70 timesRepeat: [ Stdio stderr nextPutAll: (String loremIpsum: 1024). 0.01 second wait. ] ] fork"');
	redirectStderr;
	run.

The standard streams have a maximum buffer. When this buffer is full, then the process is paused until someone reads in the buffer and empty it. OSSubprocess should handle this case by providing a way to signal that data is available. It could be done by using non-blocking ffi calls to read the buffer.

demarey avatar Jun 16 '20 13:06 demarey

Here is a test to reproduce: OSSubTest.st.txt

demarey avatar Jun 16 '20 13:06 demarey