Python解压缩大于内存的文件 - OSError:[Errno 28]设备上没有剩余空间

时间:2018-03-19 00:16:03

标签: python zip

我试图用机器8gb RAM解压缩8gb csv文件。这是我的实现,使用python 3.6:

def extract_to(zippath, dest):
with zipfile.ZipFile(zippath, mode='r') as z:
    for member in z.namelist():
        filename = Path(member).basename()
        # skip directories
        if not filename:
            continue

        source = z.open(member)
        target = open(dest / filename, "wb")
        with source, target:
            shutil.copyfileobj(source, target)

不幸的是,它会产生以下错误:

Traceback (most recent call last):
  File "download_data.py", line 31, in extract_to
    shutil.copyfileobj(source, target)
  File "/home/user/anaconda3/lib/python3.6/shutil.py", line 82, in copyfileobj
    fdst.write(buf)
OSError: [Errno 28] No space left on device

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "download_data.py", line 56, in <module>
    main()
  File "download_data.py", line 49, in main
    download_and_extract_zip(train, RAW_DATA_DIR)
  File "download_data.py", line 37, in download_and_extract_zip
    extract_to(tmppath, dest)
  File "download_data.py", line 31, in extract_to
    shutil.copyfileobj(source, target)
OSError: [Errno 28] No space left on device

我该如何处理这种情况?感谢。

0 个答案:

没有答案