-
Couldn't load subscription status.
- Fork 90
Added bytestring variants for readProcess and friends #36
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
Conversation
This allows convenient binary communication with subprocesses.
|
@hvr I haven't reviewed the code yet, but I wanted to touch base regarding the bytestring dependency. Do you know of any reason we should avoid it? |
|
I really can't think of any serious reason, really. Maybe there are people with use cases where it is absolutely vital to avoid unnecessary dependencies (idk, embedded dev maybe? Haven't done any of that, so I really have no clue what the situation is like there), but my expectation would be that TL;DR: If I were in charge, I wouldn't worry, but maybe others have pressing concerns here. |
|
Oh, and also, the build fails for GHC 7.4 and earlier (https://travis-ci.org/haskell/process/jobs/72742820), as far as I can tell this is because there is no |
|
Sounds correct on the deepseq parts. The only reason I'm concerned at all about bytestring is that I'm not familiar with the GHC build process, and don't want to cause problems there. |
Strict ByteStrings have no suitable instances for deepseq'ing on older GHC's (<= 7.4), but we don't actually need deepseq here, because BS.hGetContents is strict already. Instead, we'll do our reading and writing in concurrent threads directly, and send them back to the main thread through MVars.
|
I can't think of any reason not to depend on I'd avoid however depending on However, I would have expected lazy |
|
This last commit removes the deepseq-ing for ByteStrings, instead putting the |
|
@hvr: true, lazy bytestrings would be expected, but I'm not sure how this would play along with the "read outputs strictly" part. Re the deepseq dependency: that one was already in place in order to strictly read |
|
The data is going to be read out strictly regardless. The advantage of a lazy
OK, I'll move ahead with reviewing this code, sounds like we don't have any blockers on merge besides the code itself ;) |
|
fair enough, in the interest of some more bikeshedding, I'm slightly +1 for
=) |
Indeed - the intended behavior is "block until the child process terminates, then return stdout and stderr", which is kind of impossible with lazy reads (can't read lazily when the child process has already terminated). @hvr: Should I move the bytestring variants out then? |
|
I'm +1 on the separate module approach too, it fits nicely with other core libraries (like network). It also makes it easy to make a shim compatibility package. |
|
Alright, separated out the ByteString functions into |
|
OK, turns out I'm rather dumb: http://hackage.haskell.org/package/process-extras-0.3.3.5/docs/System-Process-ByteString.html I guess that means my pull request is moot then... |
|
@tdammers I believe you really want lazy bytestrings here. Currently your approach uses the strict For this reason you really want to use |
|
@tdammers it may still be desirable to move |
|
@snoyberg re
maybe those strictly-consuming-output functions should take a max-size parameter as an upper bound; this would encourage a more defensive programming style... |
|
Due to prior art, I'm very much tempted to take the two ByteString modules from process-extras exactly as they are to make for as easy a transition as possible. When it comes to consuming possibly-large data, I think dropping down to a |
|
For the sake of compat/transition, I would have used For me personally, those |
|
To be clear: a strict If we wanted to double down on lazy I/O (which I don't want), a function signature like the following could be added: readProcessLazily
:: CreateProcess
-> L.ByteString -- ^ stdin
-> (L.ByteString -> L.ByteString -> IO a) -- ^ inner function, takes lazy stdout and stderr
-> IO (a, ExitCode)And then the inner function will run concurrently with the process, instead of the current API which requires that the process exit before getting access to the data at all. |
|
Is everyone OK with closing this based on the presence of process-extras? |
This allows convenient binary communication with subprocesses.
Some concerns that may need addressing:
/testsseem kind of dead, or at leastcabal testdoesn't touch them, but copying theprocess006test over and changing it to use the bytestring flavors should work.