[Python] Get subprocess output in Python without overwriting progress bar

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    I'm trying to download a file in Python with wget2. It repeatedly prints the output progress bar, which as a standalone process is ok, since it returns to line beginning with \r. However, I don't know how to achieve this in Python. I need output in real time, as the file is being downloaded.

    Code:

    url = "https://ftp.ebi.ac.uk/pub/databases/chembl/ChEMBLdb/releases/chembl_35/chembl_35.sdf.gz"
    cmd = [
    "wget2",
    url,
    f"--max-threads=5",
    "-N", # re-download only updated files
    # set nice outputs
    "--no-verbose",
    "--force-progress",
    ]
    subprocess.run(cmd, check=True, stdout=sys.stdout, stderr=sys.stderr)


    Outputs:

    7[Files: 0 Bytes: 0 []
    7[https://ftp.ebi.ac.uk]87chembl_35.sdf.gz 0% [> ] 46.57K --.-KB/s87chembl_35.sdf.gz 0% [> ] 202.82K 1.22MB/s87chembl_35.sdf.gz 0% [> ] 359.07K 1.22MB/s87chembl_35.sdf.gz 0% [> ] 491.88K 1.15MB/s87chembl_35.sdf.gz 0% [> ] 679.38K 1.23MB/s87chembl_35.sdf.gz 0% [> ] 859.07K 1.26MB/s87chembl_35.sdf.gz 0% [> ] 999.69K 1.23MB/s87chembl_35.sdf.gz 0% [> ] 1.15M 1.27MB/s87Just got 1351689 of 805068706 bytes (https://ftp.ebi.ac.uk/pub/databases/chembl/ChEMBLdb/releases/chembl_35/chembl_35.sdf.gz)
    87chembl_35.sdf.gz 0% [> ] 1.28M 1.25MB/s87chembl_35.sdf.gz 0% [> ] 1.28M 1.25MB/s87[Files: 0 Bytes: 0 []8Traceback (most recent call last):


    I guess that I have to do something with Popen, but everything that I've tried just printed empty lines.

    Continue reading...

Compartilhe esta Página