commercialhaskell / commercialhaskell/stack

Respect executable NoBuffering

Open
#2,702 7 comments 0 reactions 0 assignees View on GitHub
component: benchmark type: bug
Dominant language
Haskell
Stars
4.1k
Forks
850
Avg merge
10h 37m
Merged PRs (30d)
4

Description

I explicitly adjust `hSetBuffering` in my benchmarks so that I can see incremental output. `stack bench` seems to ignore this and only produces output when a newline occurs.

foo.cabal

```
name: foo
version: 0.0.0.1
build-type: Simple
cabal-version: >= 1.10

library
default-language: Haskell2010
build-depends:
base

exposed-modules: Lib

Benchmark bench-foo
type: exitcode-stdio-1.0
default-language: Haskell2010
main-is: Main.hs
hs-source-dirs: benchmarks

build-depends:
base
```

Lib.hs

```
module Lib where
```

Main.hs

```
import Control.Concurrent
import System.IO

main :: IO ()
main = do
hSetBuffering stdout NoBuffering
putStrLn "Hello world"
putStr "Going to sleep..."
threadDelay 2000000
putStrLn "awake again!"
```

I'm using the 7.0 resolver (i.e. GHC 8.0.1).

To reproduce,

```
> stack bench foo
```

This prints "Hello world", then waits 2 seconds, then prints "Going to sleep...awake again!" and exits.
By comparison,

```
> ./.stack-work/dist/*/Cabal-*/build/bench-foo/bench-foo
```

prints "Hello world" and immediately prints "Going to sleep..." on a new line. _Then_ it waits 2 seconds and prints "awake again" on the same line, and then exits.

```
> stack --version
Version 1.2.0 x86_64 hpack-0.14.0
> cabal --version
cabal-install version 1.24.0.0
compiled using version 1.24.0.0 of the Cabal library
```

I explicitly set `hSetBuffering stdout NoBuffering` so that I could see output without a new line. I've also tried setting `stderr` to `NoBuffering`, but that didn't help either.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.