Question

Je reçois une erreur "Erreur de mémoire" lorsqu'elle est ouverte et lit un fichier de plus de 500 Mo. Si c'est moins de 500 Mo, cela fonctionne parfaitement .. Je suis en utilisant la taille de ma barre de progression Maxvalue

    self.ftp = FTP(hostname)
    self.ftp.login(user, password)
    self.f = open(self.filename,'rb')

    with open(self.filename,'rb') as filein:
        self.size = filein.read()

    self.size = len(self.size)

Était-ce utile?

La solution

Don't use the read() method since it reads the whole file into a string. You should use the os.stat() function to get the the file metadata, which returns a stat structure with the member st_size. That's the size in bytes of the file. You don't have to read it all in first.

For sending, also read in and write out in chunks (say 16kB), in a loop.

Autres conseils

So, filein.read() actually reads (i.e. downloads) the file and is consuming your memory.
You can instead use

self.size = self.ftp.size(self.filename)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top