Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Progress Finished Question
#21
Okay, it's a progress bar (sorry, I hadn't noticed the link); I'll look into it. I kind of want to write it out on my own just for the practice. Thanks for taking the time to write out an explanation. I need to know the errors to make use of it I guess?

Well, let m e see what I can come up with (or get to a point that I need help) and I'll post back with some code.
Quote
#22
You don't need to know all the error or any at all. Just test the code.
In my example, there is an input which is converted to float. Open the Python interpreter and run this line of code but instead of some number put a letter or some punctuation as an input. Produce an error on purpose. And you will see how is called.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#23
Okay, here is version 1.1:

import os, sys

def copyFunc(source, destination):
    with open(source, 'rb') as f1, open(destination, 'wb') as f2:
        fullSize = os.stat(source).st_size
        increment = 10485760
        while os.stat(destination).st_size < fullSize:
            chunk = f1.read(increment)
            f2.write(chunk)
            full = os.stat(destination).st_size
            print(round(full / fullSize * 100, 1), '%\r')

one = '397.64-desktop.exe'
two = 'C:\\Users\Mark\Downloads\Ordenador\driver.exe'
copyFunc(one, two)
I put it in a function and increased byte size to what you said, and with that, it's closer to SSD speed. I got the percentage to work better, but I'm not 100% happy. It's a WIP, for sure.
Quote
#24
The while condition is unnecessary.
Instead of calling a function on each loop you can initialise the chunk before the loop. And you will have one function call less in the script.

increment = 10485760
chunk = f1.read(increment)
        while chunk:
            f2.write(chunk)
            full = os.stat(destination).st_size
            print(round(full / fullSize * 100, 1), '%\r')
            chunk = f1.read(increment)
Alson, you can play with the 'increment' size to see what is the optimum one for your system.
Why are you not happy?

Btw, try to calculate it to see if there is any difference.

increment = 10485760
copied = 0
chunk = f1.read(increment)
        while chunk:
            f2.write(chunk)
            copied += increment
            print(round(copied / fullSize * 100, 1), '%\r')
            chunk = f1.read(increment)
malonn likes this post
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#25
Alrighty, there wavic. You're sticking with me and I appreciate it. I'll try some things and see what's what. I'm thinking "increment" is going to vary based on file size--a smaller file will reduce "increment", a larger will do the opposite. I don't know yet. Maybe I should just go for the fastest possible transfers all the time. Get what I paid for.

I'll post back with some code for you to peruse if you feel like it.
Quote
#26
Don't forget that this is an SSD. There are no moving heads so "there is no" delay in accessing the file or its parts. The fragmentation doesn't matter here. Almost. I'm not sure for the small files.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#27
Alright, this is my next version (I'm more happy with it):

import os

def copyFunc(source, destination):
    with open(source, 'rb') as f1, open(destination, 'wb') as f2:
        full_size = os.stat(source).st_size
        full = 0
        increment = 10485760
        chunk = f1.read(increment)
        while f1.read(increment):
            full += increment
            if full + increment > full_size:
                full += full_size - full
            f2.write(chunk)
            print(round(full / full_size * 100, 1), '%\r')

one = '397.64-desktop.exe'
two = 'C:\\Users\Mark\Downloads\Ordenador\driver.exe'

copyFunc(one, two)
The changes you made helped me. I didn't fully understand what was happening behind the scenes with
.read()
and
.write()
. It's good that Python tracks written size vs read size and other stuff pertaining (that I'm not understanding, TBH) to the transfer of file objects. That would be more code if the scripter had to handle him/herself.

But the above code floats my boat, so I'll move on.
Quote
#28
Don't have to be happy. This script doesn't do what you want.
Python doesn't track anything. The script stops because of in the while condition f1.read() finally doesn't return anything.
And you have written to the new destination only the first 10M of the f1. In every loop, chunk is written to f2 but it holds the same data. It never changes.

victor at Jerry in ~
↪ sha1sum '/media/storage/Download/Video/Etcher-Portable-1.3.1-x64.exe'
aea0b63b9bc0881662dd47b036a5f1324f5a6ed3 /media/storage/Download/Video/Etcher-Portable-1.3.1-x64.exe

victor at Jerry in ~
↪ sha1sum '/tmp/Etcher-Portable-1.3.1-x64.exe'
6e455cda41e2a0c4e8954f4776446c59591569c1 /tmp/Etcher-Portable-1.3.1-x64.exe

See?
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote
#29
You're partially right, in my testing. I goofed. The file to be copied does not match the file that was copied. I goofed. But the code is not precisely wrong where you think it is. While there are bytes in the copied file it writes the set chunk. Python must keep track of the stuff somehow. But it's not 100% in my testing (my eyes deceived me when I posted earlier.) All but the last 10MB (increment size) gets copied. I've to go back to the 'lab' and fix it...
Quote
#30
Don't ask me why I have in the Video directory an exe file! Big Grin
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to stop Xmodem after bin file transfer was finished shaya2103 0 126 Nov-27-2019, 04:33 PM
Last Post: shaya2103
  Process finished with exit code -107374819 (0xC0000375) mrazko 2 1,053 Apr-05-2019, 12:46 PM
Last Post: mrazko
  Fabric - Run method is not being finished mglowinski93 3 696 Dec-29-2018, 10:45 AM
Last Post: mglowinski93

Forum Jump:


Users browsing this thread: 1 Guest(s)