Hi, today I have a special request. I would like when one of my Process is running to run infinitely a function while the process isn’t finish. How can I do that ?
1 Like
I think you could probably do this via Process.new
then looping until process.terminated?
. E.g.
process = Process.new "sleep 3", shell: true
until process.terminated?
puts Time.utc
sleep 0
end
Which starts the process, then will print the current time a bunch of times until the process sleeps 3 seconds and exits. The sleep 0
is important to give an exit out of the loop when the process actually finishes. Otherwise it’ll loop indefinitely, probably because the process happens in its own fiber or something so the scheduler never has a chance to update the process info to say it actually finished. Tho really, it may not be required depending on what you’re wanting to do. E.g. other operations may also work.
4 Likes
Thank you so much