fix timer

This commit is contained in:
Rijnard van Tonder 2019-04-25 23:50:07 -04:00
parent 6f01795a61
commit 2df40597f4
2 changed files with 7 additions and 6 deletions

View File

@ -1,5 +1,3 @@
open Core
let start () = Unix.gettimeofday ()
let stop start =
@ -9,11 +7,11 @@ exception Time_out
let time_out ~after f args =
let behavior =
Signal.(Expert.signal alrm (`Handle (fun _ -> raise Time_out)))
Sys.(signal sigalrm @@ Signal_handle (fun _ -> raise Time_out))
in
let cancel_alarm () =
Unix.alarm 0 |> ignore;
Signal.(Expert.set alrm behavior)
Sys.(set_signal sigalrm behavior)
in
Unix.alarm after |> ignore;
match f args with

View File

@ -87,6 +87,7 @@ let process_single_source matcher verbose configuration source specification mat
let f () = get_matches matcher configuration match_template match_rule input_text in
Statistics.Time.time_out ~after:match_timeout f ();
with Statistics.Time.Time_out ->
Format.eprintf "Timeout for input: %s!@." (show_input_kind source);
Out_channel.with_file ~append:true verbose_out_file ~f:(fun out_channel ->
Out_channel.output_lines out_channel [Format.sprintf "TIMEOUT: %s@." (show_input_kind source) ]);
[]
@ -110,7 +111,8 @@ let process_single_source matcher verbose configuration source specification mat
Some (rewrite rewrite_template rewrite_rule input_text matches, matches)
in
Statistics.Time.time_out ~after:match_timeout f ();
with Statistics.Time.Time_out ->
with Statistics__Time.Time_out ->
Format.eprintf "Timeout for input: %s!@." (show_input_kind source);
Out_channel.with_file ~append:true verbose_out_file ~f:(fun out_channel ->
Out_channel.output_lines out_channel [Format.sprintf "TIMEOUT: FOR %s@." (show_input_kind source) ]);
None
@ -122,7 +124,8 @@ let process_single_source matcher verbose configuration source specification mat
| Some (None, _)
| None -> Nothing
with
| _ -> Nothing
| _ ->
Nothing
let output_result stdin spec_number json_pretty json_lines source_path result in_place =
match result with