From acd3b8e3a13ec255acae3765095d58d7e808765f Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 17 Dec 2016 17:28:08 -0400 Subject: 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. --- Utility/MagicWormhole.hs | 14 ++++++++------ 1 file 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 -- cgit v1.2.3