Async: Fd not getting closed?

Showing 1-3 of 3 messages
Async: Fd not getting closed? Malcolm 10/11/12 1:29 PM
I have some dirty code here:

To compile:

ocamlfind ocamlopt -package core,async -thread -linkpkg -o foo

The problem is the 'wait' never seems to come back. This appears to be
because the cat is still waiting on reading stdin.  But the stdin
should be closed on line 77, shouldn't it?

What am I doing wrong?


Re: Async: Fd not getting closed? David House 10/11/12 1:48 PM
Some general comments first:

* read_all seems to be trying to achieve the same thing as Reader.contents

* Is there any reason why you're using Core's waitpid function over

* (background foo) is equivalent to just foo, and you only
ever use the result of background inside an, so I think
background is pointless.

It's not immediately apparent where the actual bug is. One thing to
ask: do you get past the wait call, or are you getting stuck inside
one of the Deferred.both's? I.e. if you put a printf straight after
wait, do you see it? (Best to use [Printf.printf "foo\n%!"]; the
Printf module avoids going via Writer's buffer in case something weird
is going on, and you should always flush your debugging statements
with "%!"!)
Re: Async: Fd not getting closed? Malcolm 10/11/12 2:00 PM
Yes the code is in transition as I learn more about Async, so take all
non essentials with a grain of salt.

I switched the wait function to:

let wait pi =
  Unix.wait (`Pid (Core.Std.Pid.of_int >>= function
    | (_, Result.Ok ()) ->
      Deferred.return (`Exited 0)
    | (_, Result.Error (`Exit_non_zero n)) ->
      Deferred.return (`Exited n)
    | (_, _) ->
      Deferred.return `Unknown

with no change in behaviour.

I do not get past the wait call and a ps shows the cat is still
running.  This function works properly for a program that doesn't read
from stdin such as an ls, which is what leads me to think somehow
stdin is not getting closed properly.

Thanks for the quick response,