From b66cddbe4d955d084e6774e76839e6b8dda041d4 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 3 Mar 2016 13:57:33 +0100 Subject: [PATCH] Cleaning after Ctrl-C --- ocaml/Qmcchem_dataserver.ml | 3 ++- ocaml/Qmcchem_forwarder.ml | 6 +++--- ocaml/Qmcchem_run.ml | 8 ++++---- ocaml/Watchdog.ml | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ocaml/Qmcchem_dataserver.ml b/ocaml/Qmcchem_dataserver.ml index afd4a8a..f63c21b 100644 --- a/ocaml/Qmcchem_dataserver.ml +++ b/ocaml/Qmcchem_dataserver.ml @@ -833,12 +833,13 @@ let run ?(daemon=true) ezfio_filename = (* Handle signals *) let handler s = + Printf.printf "Dataserver received the %s signal... killing\n%!" (Signal.to_string s); Watchdog.kill (); in List.iter [ + Signal.int ; Signal.term ; Signal.quit ; - Signal.int ] ~f:(fun x -> Signal.Expert.handle x handler) ; diff --git a/ocaml/Qmcchem_forwarder.ml b/ocaml/Qmcchem_forwarder.ml index 4a421f3..041b38f 100644 --- a/ocaml/Qmcchem_forwarder.ml +++ b/ocaml/Qmcchem_forwarder.ml @@ -71,6 +71,7 @@ let run ezfio_filename dataserver = let terminate () = (* Clean up the temp directory *) + Watchdog.kill (); Unix.chdir Qmcchem_config.dev_shm; let command = Printf.sprintf "rm -rf -- \"%s\" " tmpdir @@ -96,14 +97,13 @@ let run ezfio_filename dataserver = (* Signal handler to Kill properly all the processes *) let handler s = - Printf.printf "Forwarder received the %s signal... killing\n" (Signal.to_string s); + Printf.printf "Forwarder received the %s signal... killing\n%!" (Signal.to_string s); terminate (); - Watchdog.kill (); in List.iter [ + Signal.int ; Signal.term ; Signal.quit ; - Signal.int ] ~f:(fun x -> Signal.Expert.handle x handler) ; diff --git a/ocaml/Qmcchem_run.ml b/ocaml/Qmcchem_run.ml index f878987..03d9bc1 100644 --- a/ocaml/Qmcchem_run.ml +++ b/ocaml/Qmcchem_run.ml @@ -7,8 +7,8 @@ let full_run ?(start_dataserver=true) ezfio_filename = and scheduler = Scheduler.find () in - Printf.printf "Scheduler : %s\n" (Scheduler.to_string scheduler); - Printf.printf "Launcher : %s\n" (Launcher.to_string launcher ); + Printf.printf "Scheduler : %s\n%!" (Scheduler.to_string scheduler); + Printf.printf "Launcher : %s\n%!" (Launcher.to_string launcher ); (* Create the node file *) @@ -147,13 +147,13 @@ let run a d ?q ?s ezfio_filename = (* Signal handler to Kill properly all the processes *) let handler s = - Printf.printf "Received the %s signal... killing\n" (Signal.to_string s); + Printf.printf "QMC=Chem received the %s signal... killing\n%!" (Signal.to_string s); Watchdog.kill (); in List.iter [ + Signal.int ; Signal.term ; Signal.quit ; - Signal.int ] ~f:(fun x -> Signal.Expert.handle x handler) ; diff --git a/ocaml/Watchdog.ml b/ocaml/Watchdog.ml index a9d2e3d..3a6a0aa 100644 --- a/ocaml/Watchdog.ml +++ b/ocaml/Watchdog.ml @@ -8,7 +8,7 @@ let _threads = ref [] ;; let kill () = let kill pid = Signal.send_i Signal.int (`Pid pid); - Printf.printf "Killed %d\n" (Pid.to_int pid) + Printf.printf "Killed %d\n%!" (Pid.to_int pid) in List.iter ~f:kill (!_list); exit 1