haskell - Control.Concurrent.Async.race and runInteractiveProcess -


i'm using race function async package, exported control.concurrent.async.

the subtasks fire off using race invoke runinteractiveprocess run (non-haskell) executables. idea run different external programs , take result of first 1 finish. in sense, haskell "orchestrates" bunch of external programs.

what i'm observing while race works correctly killing haskell level "slower" thread; sub-processes spawned slow thread continue run.

i suspect expecting race kill processes spawned way bit unrealistic, become zombies , inherited init. purposes however, keeping external processes running defeats whole purpose of using race in first place.

is there alternative way of using race subprocesses created way killed well? while don't have use case yet, it'd best if entire chain of processes created raced tasks killed; 1 can imagine external programs creating bunch of processes well.

as mentioned in comments, use combination of onexception , terminateprocess.

my process-streaming library (which contains helper functions built on top of process , pipes) this. asynchronous exceptions trigger termination of external process.

for example, following code not create file toolate.txt.

import qualified pipes.bytestring b import system.process.streaming import control.concurrent.async  main :: io () main =       result <-  race (runprogram prog1) (runprogram prog2)     putstrln $ show $ result       -- collecting stdout , stderr bytestrings     runprogram = simplesafeexecute $ pipeoe $                         separated (surely b.tolazym) (surely b.tolazym)     prog1 = shell "{ echo aaa ; sleep 2 ; }"     prog2 = shell "{ echo bbb ; sleep 7 ; touch toolate.txt ; }" 

the result is:

left (right ("aaa\n","")) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -