Showing Progress Bar
frank at chagford.com
Sat Nov 23 13:11:46 CET 2013
"Himanshu Garg" <hgarg.india at gmail.com> wrote in message
news:b4b7cf70-07fa-455a-b01f-cb69b9402bc0 at googlegroups.com...
>I want to show simple dots while my program copies the files. I have found
>the code like:
> for i in range(10):
> print '.',
> But this will execute ten times as it is predefined and the task to copy
> will execute after or before this loop based on the location I have placed
> my line to copy the files using shutil.copy().
> I want that the files should be copied and in parallel the progress should
> be shown and when the files are copied, the progress should exit.
Ned has shown how to view the dots as they are printed, but has not
addressed the 'parallel' aspect.
Here is one approach, which uses the threading module to print the dots in a
separate thread while the main thread does the copying.
In a separate thread, print dots to the screen until terminated.
self.event = threading.Event()
event = self.event # make local
while not event.is_set():
event.wait(1) # pause for 1 second
Before starting the copy -
progress_bar = ProgressBar()
When the copy is finished -
More information about the Python-list