Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Progress Finished Question
#1
Hi all. First post, very new to Python and programming in general. K, now the question:
I have this script:
import sys, shutil, subprocess, ffmpy

def getDimensions(inputVideo):
    args = '-v error -select_streams v:0 -show_entries stream=width,height ' \
           '-of compact'
    call = ffmpy.FFprobe(r'E:\\App Back-Ups\FFprobe\ffprobe.exe', args, \
                         {inputVideo : None})
    return call.run(None, subprocess.PIPE)

def getHeight(tupleIn):
    a = str(tupleIn[0])
    b = a.rfind('=')
    return a[b + 1:b + 4]

toMove = sys.argv[1]
output = getDimensions(toMove)
height = getHeight(output)
if height == '480':
    pathStr1 = 'E:\\My Movies\DVD Rips\\'
    pathStr2 = 'G:\\My Movies\DVD Rips'
else:
    pathStr1 = 'E:\\My Movies\Blu-ray Rips\\'
    pathStr2 = 'G:\\My Movies\Blu-ray Rips'

lastSep = toMove.rfind('\\')
toCopy = pathStr1 + toMove[lastSep + 1:]
shutil.move(toMove, pathStr1)
shutil.copy(toCopy, pathStr2)
input('Press \'Enter\' to exit...')
sys.exit()
It works fine, but sometimes the movie file sizes are quite large and they take a while to copy. I'm wondering how to add a progress bar or percent (preferable) to the runtime. I'm stuck figuring out how because shutil pauses while it's processing the move/copy and does not pick up the next line of script until after it has finished the copy. So, is it possible to add a simple percentage copied output to this script? Just so I know how much is done and how much more is left.
Reply
#2
Think about what you're asking. How can you know % done if you have no communication from the program that is using the time?
Reply
#3
I guess you can't? I know that shutil has no function that returns progress complete. I was thinking I could compare the size of the file with how much has been copied/moved as it happens. But, the script pauses at the copy/move functions until the file operation is done.
Reply
#4
Well, you can run shutil.copy/move in a separate thread and compare the file size against the destination file and do some math to get the percentage or some other measure. You can use this and pass it to the tqdm module for example.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
Sweet! Thanks, @wavic. I'm about as noob as they come so know nothing about threads, but Google and the official docs do. I'll look into this further.
Reply
#6
Consider that it will takes some time to check the size of copied file and compare it during to copying process. So the value will have a small difference.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#7
So, it won't be terribly accurate? Average file size is about 6GB.
Reply
#8
It will be fine.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#9
Great. I must confess, threading makes my brain hurt. It's a lot for a greenhorn noob. Oh well. Thanks again, @wavic.
Reply
#10
I am not very familiar with threading because I didn't use it.
The simplest approach:

import thread

source = '/path/big_file.BIG'
dest_path = '/path'
thread.start_new_thread(shutil.copy, (source, dest_path))
You provide the callable and the arguments to the start_new_thread method and that's all.
But this won't tell you if the copping is finished.

Better see this. It's basically almost the same. On top
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Process finished with exit code 137 (interrupted by signal 9: SIGKILL) erdemath 2 9,388 Apr-18-2022, 08:40 PM
Last Post: erdemath
  Progress bar bnadir55 1 1,781 Apr-11-2022, 01:52 PM
Last Post: deanhystad
  Using .hdf5 files only once they are finished writing pyhill00 7 2,722 Nov-25-2021, 06:01 PM
Last Post: pyhill00
  How to check if a file has finished being written leocsmith 2 7,694 Apr-14-2021, 04:21 PM
Last Post: perfringo
  Progress Indicator for Xmodem 0.4.6 KenHorse 1 1,931 Jan-30-2021, 07:12 PM
Last Post: bowlofred
  process finished with exit code -1073741819 (0xC0000005) GMCobraz 8 5,310 Sep-01-2020, 08:19 AM
Last Post: GMCobraz
  How to stop Xmodem after bin file transfer was finished shaya2103 0 2,477 Nov-27-2019, 04:33 PM
Last Post: shaya2103
  How can I add a progress bar for my software? aquerci 8 3,695 Nov-16-2019, 04:20 PM
Last Post: aquerci
  wget progress bar anasrocks 1 4,691 Jun-06-2019, 03:12 PM
Last Post: heiner55
  Process finished with exit code -107374819 (0xC0000375) mrazko 2 8,400 Apr-05-2019, 12:46 PM
Last Post: mrazko

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020