[Python] AttributeError: 'zstd.ZstdDecompressionReader' object has no attribute 'fileno'

Discussão em 'Python' iniciado por Stack, Julho 4, 2025.

  1. Stack

    Stack Membro Participativo

    I need to run a subprocess pipeline that uses zstandard files (too large to fit in memory) both as their input and output. Consider the following example:

    import subprocess
    import zstandard

    with zstandard.open('a.txt.zst', 'w') as f:
    f.write('hello\n')

    f_in = zstandard.open('a.txt.zst', 'rb')
    f_out = zstandard.open('b.txt.zst', 'wb')

    # in reality I'd be running multiple programs here by chaining PIPEs, but first
    # reads f_in and last writes to f_out:
    subprocess.call(['cat'], stdin=f_in, stdout=f_out)


    I'm getting the following error:

    Traceback (most recent call last):
    File "/tmp/a.py", line 12, in <module>
    subprocess.call(['cat'], stdin=f_in, stdout=f_out)
    File "/usr/lib/python3.11/subprocess.py", line 389, in call
    with Popen(*popenargs, **kwargs) as p:
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3.11/subprocess.py", line 892, in __init__
    errread, errwrite) = self._get_handles(stdin, stdout, stderr)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3.11/subprocess.py", line 1661, in _get_handles
    p2cread = stdin.fileno()
    ^^^^^^^^^^^^
    AttributeError: 'zstd.ZstdDecompressionReader' object has no attribute 'fileno'


    I'm thinking of using PIPEs at both ends and feeding them with threads, but it feels rather fragile. Is there a more idiomatic solution to this problem?

    Continue reading...

Compartilhe esta Página