-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pipe blocking when input too large? (Mac OS) #218
Comments
The library is behaving correctly in this case. When you use |
Thanks for the explanation! Makes perfect sense now. Consequently, here is the correct implementation of the pipe, which indeed works as expected: main = do
(Just inp, Just out, _, ph1) <- createProcess $
(proc "cat" [])
{ std_in = CreatePipe
, std_out = CreatePipe
}
(_, _, _, ph2) <- createProcess $
(proc "less" [])
{ std_in = UseHandle out }
-- After the pipe is set up, we can pour the input without blocking:
hPutStr inp longInput
hClose inp
waitForProcess ph1
waitForProcess ph2
putStrLn "Program terminated successfully."
where
longInput = unlines $ replicate 10000 $ replicate 63 'A' Alternatively, writing to import Control.Concurrent.Async
import System.IO
import System.Process
main = do
(Just inp, Just out, _, ph1) <- createProcess $
(proc "cat" [])
{ std_in = CreatePipe
, std_out = CreatePipe
}
withAsync (hPutStr inp longInput >> hClose inp) $ \_ -> do
(_, _, _, ph2) <- createProcess $
(proc "less" [])
{ std_in = UseHandle out }
waitForProcess ph1
waitForProcess ph2
putStrLn "Program terminated successfully."
where
longInput = unlines $ replicate 10000 $ replicate 63 'A' I wonder whether this example could be added as tutorial somewhere to the documentation (I can do this if it is welcome). Previously, I had googled a lot but did not find enough examples for |
I’m certainly up for such a doc addition. At the very least, a “make sure you don’t deadlock by filing buffers” with a link to this issue would be great. |
In simulating (
cat | less
) usingcreateProcess
andCreatePipe
, I am experiencing a weird threshold on the input tocat
. This is shrunk from a real world problem.Using the
good
input,less
shows up presenting me the 2304 lines of 63A
s each.Using the
bad
input, nothing shows up, and I can only Ctrl-C.This is on Mac OS Mojave with GHC 9.0.1 and latest
process
(1.6.13.2).In my original setting, the pipe was
nroff -man /dev/stdin | less
and the threshold was exactly 192kb (192 * 1024 bytes).Note that there is no problem if I let the OS do the piping (using
shell "cat | less"
):The text was updated successfully, but these errors were encountered: