Showing dot each second until the script ends

H

Hunt Jon

I have a ruby script, which takes about 20 seconds to execute.

I want to show a dot (.) sign each second.

I think I need to use "sleep" method and a loop,
but I don't know how to add the functionality to my script.

Any help would be appreciated.
 
R

Robert Klemme

2009/8/21 Hunt Jon said:
I have a ruby script, which takes about 20 seconds to execute.

I want to show a dot (.) sign each second.

I think I need to use "sleep" method and a loop,
but I don't know how to add the functionality to my script.

Any help would be appreciated.

Here's one way: create a separate thread that loops infinitely and
does the sleeping and printing.

Kind regards

robert
 
H

Harry Kakueki

I have a ruby script, which takes about 20 seconds to execute.

I want to show a dot (.) sign each second.

I think I need to use "sleep" method and a loop,
but I don't know how to add the functionality to my script.

Any help would be appreciated.

If you want to do that I think you would need a thread for that purpose.
Does your script now print nothing for that 20 seconds?

If so, you could print a dot after each step of your program finishes.
Then when you see the last dot, it will be finished, whether it took
19 seconds or 22 seconds, or whatever.
Just a suggestion.

(0..3_000_000).to_a #Fake busy time
print "."
STDOUT.flush

(0..3_000_000).to_a #Next process, etc.
print "."
STDOUT.flush

(0..3_000_000).to_a
print "."
STDOUT.flush

(0..3_000_000).to_a
print "."
STDOUT.flush

puts


Harry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top