On 2008 Nov 10, at 16:29, Jason Dusek wrote:
 I've put together a simple test case for a rather annoying
 problem. I've got a program that drives other programs. For
 example, it can drive `cat`:

:; Simple cat a-file

 When the file is a little bit greater than 135060 bytes, this
 program fails to produce any output at all -- I need to use ^C
 to get my console back.

If you are feeding it input and collecting output, you need to forkIO one or both. In particular, the sequence

        feed input
        read output
        waitForProcess

will deadlock if at any point the input or output pipe fills: one side will be blocked on write() waiting for the other side to read() from the pipe, while the read() side is blocked waiting for write() on the other pipe, which won't be read() because that's the first side.

(There are other variants of this, but that's the general form: processes blocked each waiting for the other side to do something.)

 If I remove the `hClose`, the example program just hangs, no
 matter the size of the input.

That's another symptom of it, yes, made worse because the pipe close is now implicit and the other side won't stop read()ing until the pipe is close()d by the first side.

simple exe bytes args        =  do
(i, o, e, p) <- runInteractiveProcess exe args Nothing Nothing
   hPut i bytes
   s                       <-  hGetContents o
   hClose i
   return s

Yep, that's your problem.  forkIO the hPut.

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon university    KF8NH


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to