-
Notifications
You must be signed in to change notification settings - Fork 88
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
"Shellish" behaviour on Mac OS X 10.8 and GHC 7.6.3 #35
Comments
This behavior is seen in cabal-meta which uses shelly: yesodweb/cabal-meta#20 It works on Linux for me, so I am puzzled as to what went wrong. I will have a Windows computer in a few days that I can also test out. |
Interesting, apparently it seems a Mac OS X thing. I have a Linux box on Amazon, I will give it a spin there to see if I can reproduce the error. |
I was able to reproduce the problem on the Linux box too. Even more interesting is, I've tried on Mac OS X with GHC 7.4: same problem. I'm wondering then where the problem might lie. |
Ok, after an afternoon of hacking I think I've restricted the area were the problem is, even though it doesn't explain why you are not able to replicate the problem or why the problem has popped up all of sudden. Anyway, if we look here: https://github.com/yesodweb/Shelly.hs/blob/master/Shelly.hs#L230 And we put a Debug.traceIO "waiting"
line <- TIO.hGetLine readHandle
Debug.traceIO "got " ++ show line
TIO.hPutStrLn writeHandle line >> go (foldLine acc line) But again, whilst "waiting" is printed straight away, got" is printed after the command terminates. This make me think we remain stuck on the |
My suspect were true, it was something handle-related, and might be also related to the way different OS handles processes and pipes. This is a quick hack to demonstrate how to make the library display the output as we progress (tested just on the above program). We need to change the way we create the stdout handle in https://gist.github.com/adinapoli/5582382#file-gistfile1-hs-L270 HTH to debug the issue further! |
Another update (sorry for these stream-of-consciousness-like comments): interestingly, the problem is extended to standard input too. To test it, try to create a Shelly program which call "cabal init". On my machine, it was waiting for the first user input and then it hung waiting for the second input (package version). The solution to make it work properly was to get rid of a) We are not handling correctly the corner case of creating this pipe. Maybe we need to say something like "if it's the first process Inherit, otherwise create a pipe", or something like that b) Pass our on c) The |
Won't inheriting break down in a multi-threaded environment? Thanks for keeping on this. I am going to try finishing the conversion to strict Text first. |
Well, I actually don't know yet, but one thing is sure: with the current As regards strict Text, I was planning to get rid of the callback and using maybe a conduit to sink our stdout messages, which we can fetch later on :) |
Btw, I've found a bug with my patch (using Inherit): the text is displayed, but using the stdout to both read and write is simply not possible (stdout is created by the system ad a WriteMode pipe). This implies that, even though we see the output as it gets generated, we can't fold it, because as soon as we try to read something inside {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ExtendedDefaultRules #-}
module RunSpec (runSpec) where
import Test.HUnit hiding (path)
import Test.Hspec
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ < 706
import Prelude hiding ( FilePath, catch )
#else
import Prelude hiding ( FilePath )
#endif
import Shelly
runSpec :: Spec
runSpec = do
describe "run should" $ do
it "return the full stdout" $ do
res <- shelly $ escaping False $ run "ls" ["*.hs"]
res @?= "Setup.hs\n"
I need more time to figure out a solution which will both show the output AND concatenate it correctly. Reverting the createProcess to use pipes makes the test pass, but expose again the reported bug of the delayed output. |
There should be a way to dup a handle. Friday starts the Haskell hackathon: I will have time to figure things out then. |
Nice stuff, let's keep each other posted :) |
Any improvement on this? I'm kinda stuck, so I was hoping in some enlightenment of yours :) |
sorry, broke my arm 2 weeks ago when this issue was left off. but I have time to look at things this weekend now. |
Oh, sorry for that :S hope you're right now :) A. |
I just pushed a branch 1.0-alpha with your changes (thanks!) except the switch to inherit. It also includes the new |
I added a drain test onto the 1.0-alpha branch. I am not reproducing the problem, can you change the test as needed to reproduce the problem on your end? |
Sure, I'll do! Just for curiosity, can you post your GHC version and your Machine distros and Kernel? |
Ok, if you merge my branch "shelly-1.0" and try to run "testall" you'll see that the program crashes when trying to use the run function now. Not sure if is the result of a wrong merge of mine, or a side effect of the new https://github.com/adinapoli/Shelly.hs/tree/shelly-1.0 Do you mind giving it a shot? |
Inherit is not a solution to this problem and is instead creating new bugs or maybe you have a merge issue. RunSpec works fine for me on 1.0-alpha so I don't think it is a useful test.. Please use the 1.0-alpha branch which has all your changes except for Inherit. I still do not have a test case demonstrating the original problem: if you can modify the drain test to reproduce it that would be very helpful. |
ghc 7.6.3 (but previously I was using 7.4) uname -a
I am on Ubuntu 13.04 but was previously using 12 |
Sorry Greg, but I think you overlooked the fact I'm indeed using your branch, I've just merged your branch into mine preferring your edits in case of conflicts. The fact I'm using CreatePipe is witnessed here: https://github.com/adinapoli/Shelly.hs/blob/shelly-1.0/src/Shelly.hs#L278 Why you say RunSpec is not a meaningful test? It test that whenever we run an external command, we are correctly writing all the output into a Sh Text monad, but apparently this is not the case. So either I had a bad merge or we are getting two different results on two different machines. |
Bear also in mind you have assigned (I think) a wrong versioning: https://github.com/yesodweb/Shelly.hs/blob/1.0-alpha/shelly.cabal#L3 Due to the fact 0.1.0.0 < 0.15 (is it?) it will never be installed by "cabal install". Shouldn't it be |
Perfect, it was a bad merge, now RunSpec passes. I will commit soon on my branch, which not only includes your 1.0-alpha, but correct the aforementioned version quirk :) Edit: it's in in case you wanna merge it: https://github.com/adinapoli/Shelly.hs/tree/shelly-1.0 |
@gregwebs out of curiosity, have you ever got to the bottom of this? |
no. I use Linux so I haven't seen it. If you can give me a test case that reproduces this on Mac I can try to solve it. |
Good news, on the latest Shelly I wasn't able to reproduce it. |
Thanks for the report! My guess is that your GHC version or line encoding setting may have changed. |
The version is the same, I'm on Maverick now though. |
Seems like this problem resolved itself. Maybe it was in some dependency or in GHC. |
Hello guys,
in the past (I'm the guy of the "Testimonials" link) I've used Shelly without problems (Linux and GHC 7.4, I'm pretty sure), but now on Mac OS X 10.8 and GHC 7.6.3 I'm experiencing the old Shellish behaviour, namely the output is visible only after the command has been completed. To demostrate this (at least on my particular environment) I've whipped up this small program:
What happens is that the echo is printed immediately, whilst the program remain "stuck" on cabal update for a while, and then it print in "burst":
My first thought was that something changed codewise since I've used Shelly, or it's the platform/ghc version to do the difference.
Any idea?
Thanks!
A.
The text was updated successfully, but these errors were encountered: