문제

열어 500MB보다 큰 파일을 열고 읽을 때 '메모리 오류'오류가 발생합니다. 500MB 미만이면 완벽하게 작동합니다 .. 내 진행률 막대의 크기를 사용하는 IM 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)
.

도움이 되었습니까?

해결책

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.

다른 팁

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top