craigfe / progress

Progress bar library for OCaml

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Interaction with fork.

pveber opened this issue · comments

I have a program that forks repeatedly inside a Progress.with_reporter call, and it seems each time it happens, there's a return carriage that gets printed to the screen. Next time the bar is rendered, it is added below the former render, instead of replacing it, like in:

Processing alignments  0/10 [------------------------------------------------------------------------------------------------------------------] 00:02
Processing alignments  1/10 [###########-------------------------------------------------------------------------------------------------------] 00:33
Processing alignments  2/10 [######################--------------------------------------------------------------------------------------------] 00:34

I'm not absolutely sure this is due to forking, but I highly suspect it. I see no reason for this, however. Maybe there's something I could call in the child process to disable any further interaction with the terminal?

I think this is due to the default hide_cursor which registers an at_exit handler that prints a newline and re-enables the cursor.
Try this, it fixed the problem for me:

let config = Progress.Config.v ~hide_cursor:false () in
Progress.with_reporters ~config 

This could probably be fixed by checking the pid of the process in at_exit, and only running the at_exit handler if it matches the PID of the process it got registered in.