Strange problem reading binary file data from network

Viewed 136

I have a very simple python script which reads file data and calculates the number of bytes read.

#!/usr/bin/env python

import sys, os

file_path = sys.argv[1]
expected_size = os.stat(file_path).st_size
read_size = 0
with open(file_path, 'rb') as source:
    while True:
        chunk = source.read(1024 ** 2)
        if not chunk:
            break
        read_size += len(chunk)
print(expected_size, read_size)

Effectively this script calculates the size of file in bytes using two different methods, and, as strange as it is, the reported numbers are sometimes different.

My colleague (he is using windows with python 3.5 installed) runs this script specifying path to the file on network and gets the following result:

571013088 571340768 <- second number is "incorrect" here

If he copies the file from network to local disk, the result is as expected:

571013088 571013088

I run the same script on my linux workstation, the result is always correct.

(original script was a little more useful: it copied files from network share displaying progress bar. The result was that copied file is corrupted.)

The same problem happens with many different files (probably with all quite large files).

Any ideas how to investigate what's going on?

0 Answers
Related