Printf.eprintf
is not "blocked", it's just that the buffering parameters are changed and often messages do not display before the end of the program. You should try eprintf "something\n%!"
(%!
means "flush"), but yes it's better to use Lwt_io
.
For the database, I don't know, you did not say which library you're using (at least the one called ocaml-mysql
is not Lwt-friendly, so it may require using Lwt_preemptive
).
Edit
Your:
Lwt_preemptive.detach (fun () -> Db.call) ()
This call creates a thread that, once executed, returns immediately the function Db.call
. So, basically in that case Lwt_preemptive.detach
does nothing :)
I don't know ocaml-mysql but if:
Db.call: connection_params -> connection_handle
you would have
let lwt_db_call connection_params =
Lwt_preemptive.detach Db.call connection_params