moving files in a seperate thread (and/or with progress?)

kyosohma at gmail.com kyosohma at gmail.com
Wed Aug 15 12:07:16 EDT 2007


On Aug 15, 4:28 am, "Jorgen Bodde" <jorgen.maill... at gmail.com> wrote:
> Hi all,
>
> I want to make a small batch copy tool that scans for certain files,
> and copies them to a specified directory. Since the files are huge
> (AVI / DIVX) typical 300 to 700 Mb, I want to provide the user with
> some feedback during the file copy.
>
> Here is my dillemma; When I use shutil.move(..,..) I have to wait
> until it's done, there is no feedback, so the GUI basically hangs.
> However, shutil.move can be fast because it intelligently renames the
> file when it is on the same medium, but slow when it moves to a
> different one.
> When I use my own implementation of a move mechanism that provides
> feedback, I lose that intelligence, and I might slow down the copy
> process unneccessarily.
>
> When I move files, feedback is handy to have, but not neccesary so I
> thought I can also call shutil.move from a seperate thread so the main
> GUI stays responsive. What are my options in aborting a move by
> killing the thread or are there other (3rdparty) modules I might use
> to get better move or copy performances?
>
> Just opening the file, performing a block copy myself seems like it
> will slow down the transfer, but up until now I found no way to move
> or copy with progress or abilities to abort the file transfer..
>
> Any ideas?
>
> Regards,
> - Jorgen

What GUI toolkit are you using? I know that wxPython has a status
widget that could be updated in a thread and it has some good examples
of using threads with long running tasks. I created a program with it
that deletes folders and updates me on its progress.

You can see the wxPython implementation here: http://wiki.wxpython.org/LongRunningTasks

Their widget is called a ProgressDialog. I think there's a custom one
too...

Mike




More information about the Python-list mailing list