diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-12-17 17:28:08 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-12-17 17:28:08 -0400 |
commit | acd3b8e3a13ec255acae3765095d58d7e808765f (patch) | |
tree | 804666b368f81c68eaf0b28606f82fea53d7cb7f /Utility | |
parent | 2d631990bbd24c4b6fbb317fc9308da5f7bfa196 (diff) |
use PYTHONUNBUFFERED to force python to use sane stdout buffering
Works around https://github.com/warner/magic-wormhole/issues/108
See http://stackoverflow.com/questions/107705/disable-output-buffering
for the gory details. Why a scripting language would chose a default
stdout buffering that differs between terminal and piped output, and
tends to introduce this kind of bug, I don't know.
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/MagicWormhole.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Utility/MagicWormhole.hs b/Utility/MagicWormhole.hs index 8a3758361..9cf101c5e 100644 --- a/Utility/MagicWormhole.hs +++ b/Utility/MagicWormhole.hs @@ -12,6 +12,7 @@ import Utility.SafeCommand import Utility.Monad import Utility.Misc import Utility.FileSystemEncoding +import Utility.Env import System.IO import System.Exit @@ -58,13 +59,14 @@ sendCode = putMVar -- -- A request to make the code available in machine-parsable form is here: -- https://github.com/warner/magic-wormhole/issues/104 --- --- XXX This currently fails due to --- https://github.com/warner/magic-wormhole/issues/108 sendFile :: FilePath -> CodeObserver -> WormHoleParams -> IO Bool -sendFile f o ps = runWormHoleProcess p $ \_hin hout -> do - fileEncoding hout - findcode =<< words <$> hGetContents hout +sendFile f o ps = do + -- Work around stupid stdout buffering behavior of python. + -- See https://github.com/warner/magic-wormhole/issues/108 + environ <- addEntry "PYTHONUNBUFFERED" "1" <$> getEnvironment + runWormHoleProcess p { env = Just environ} $ \_hin hout -> do + fileEncoding hout + findcode =<< words <$> hGetContents hout where p = wormHoleProcess (Param "send" : ps ++ [File f]) findcode [] = return False |