lwt
lwt copied to clipboard
Pooling processes on Windows raised Bad file descriptor (waitpid) error.
Hi,
I have an example of code that runs perfectly fine on Linux and is broken on Windows. A simplified version of the code is the following one.
let worker invocation =
let open Lwt in
let worker = Lwt_process.open_process_none invocation in
Lwt_unix.waitpid [(* Unix.WUNTRACED *)] worker#pid >>=
begin
fun (pid,status) ->
return ()
end
let main cores jobs =
let pool = Lwt_pool.create cores Lwt.return in
let f job () = worker job in
let e = Lwt_list.iter_p (fun job -> Lwt_pool.use pool (f job)) jobs in
Lwt_main.run e
On Linux, jobs are properly created and there are never more than cores
jobs running at once. On Windows, all the jobs are launched at once and then, I get a Bad file descriptor (waitpid) error. What could be going wrong?
I can solve this issue using Lwt_unix.system, or the like, but I would really like to know what is going wrong here.
IIRC Lwt_process
already does a waitpid
. Multiple waitpid
might just not be possible on windows.
Instead of calling manually waitpid worker#pid
you should use worker#status
(might be a different method name) which does the same thing.