From 9fede1e06c1a7f4265e8f7512a3dacc0ecf4a1e6 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 15 Apr 2020 23:59:17 +0200 Subject: [PATCH] Fixed do_run --- ocaml/Qmcchem_forwarder.ml | 41 ++++++++++++++------------------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/ocaml/Qmcchem_forwarder.ml b/ocaml/Qmcchem_forwarder.ml index 11b27ee..dfe0a96 100644 --- a/ocaml/Qmcchem_forwarder.ml +++ b/ocaml/Qmcchem_forwarder.ml @@ -54,6 +54,7 @@ let run ezfio_filename dataserver = | Unix.Unix_error _ -> begin Unix.chdir tmpdir; + Unix.sleep 1; if Sys.file_exists "PID" then begin let pid = @@ -80,7 +81,7 @@ let run ezfio_filename dataserver = Unix.getpid () |> Printf.sprintf "%d\n" |> output_string oc - ; + ; close_out oc; (* Fork a qmc *) ignore @@ @@ -94,6 +95,18 @@ let run ezfio_filename dataserver = let terminate () = (* Clean up the temp directory *) Unix.chdir Qmcchem_config.dev_shm; + Zmq.Context.terminate zmq_context ; + for i=port to port+4 + do + let filename = + Printf.sprintf ":%d" i + in + try + Sys.remove filename + with + | _ -> () + ; + done; let command = Printf.sprintf "rm -rf -- \"%s\" " tmpdir in @@ -102,18 +115,6 @@ let run ezfio_filename dataserver = with | Unix.Unix_error _ -> print_endline "Unable to remove temporary directory" ; - Zmq.Context.terminate zmq_context ; - for i=port to port+4 - do - let filename = - Filename.concat Qmcchem_config.dev_shm (Printf.sprintf ":%d" i) - in - try - Unix.unlink filename - with - | _ -> () - ; - done; Watchdog.kill () in @@ -121,7 +122,7 @@ let run ezfio_filename dataserver = (* Signal handler to Kill properly all the processes *) let handler s = Printf.printf "Forwarder received signal %d... killing\n%!" s; - terminate (); + terminate () in List.iter (fun s -> ignore @@ Sys.signal s (Sys.Signal_handle handler)) [ @@ -154,9 +155,6 @@ let run ezfio_filename dataserver = Printf.sprintf "ipc://%s:%d" Qmcchem_config.dev_shm (port+1); in bind_socket "PUB" pub_socket address; - at_exit (fun () -> - Sys.remove (Printf.sprintf "%s:%d" Qmcchem_config.dev_shm (port+1)) - ); let sub_socket = Zmq.Socket.create zmq_context Zmq.Socket.sub @@ -203,9 +201,6 @@ let run ezfio_filename dataserver = Printf.sprintf "ipc://%s:%d" Qmcchem_config.dev_shm (port+3); in bind_socket "XSUB" sub_socket address; - at_exit (fun () -> - Sys.remove (Printf.sprintf "%s:%d" Qmcchem_config.dev_shm (port+3)) - ); let pub_socket = Zmq.Socket.create zmq_context Zmq.Socket.xpub @@ -373,9 +368,6 @@ let run ezfio_filename dataserver = Printf.sprintf "ipc://%s:%d" Qmcchem_config.dev_shm (port); in bind_socket "ROUTER" router_socket address; - at_exit (fun () -> - Sys.remove (Printf.sprintf "%s:%d" Qmcchem_config.dev_shm port) - ); Zmq.Socket.set_receive_high_water_mark router_socket 100000; Zmq.Socket.set_send_high_water_mark router_socket 100000; Zmq.Socket.set_immediate router_socket true; @@ -396,9 +388,6 @@ let run ezfio_filename dataserver = Printf.sprintf "ipc://%s:%d" Qmcchem_config.dev_shm (port+2); in bind_socket "PULL" pull_socket address; - at_exit (fun () -> - Sys.remove (Printf.sprintf "%s:%d" Qmcchem_config.dev_shm (port+2)) - ); (* Handles messages coming into the ROUTER socket. *)