How Can I handle subprocess when a process is killed by lack of memory?

23 Views Asked by At

I'm trying to handle an error when a subprocess doesn't run because of a lack of memory. However, no exception is working in this case. What should I use?

ribodetector = [
    "ribodetector_cpu",
    "-t",
    str(threads),
    "-l",
    read_lenght,
    "-e",
    "rrna",
    "--chunk_size",
    "256",
]

# Determine which input FASTQ files to use based on file existence
if os.path.isfile(sra_filtered):
    ribodetector.extend(["-i", sra_filtered, "-o", sra_ribodetector_filtered])

elif os.path.isfile(sra_filtered_1):
    ribodetector.extend(
        [
            "-i",
            sra_filtered_1,
            sra_filtered_2,
            "-o",
            sra_ribodetector_filtered_1,
            sra_ribodetector_filtered_2,
        ]
    )

command = " ".join(ribodetector)
print(f"The command used was: {command}")

try:
    subprocess.run(ribodetector, check=True)
except subprocess.CalledProcessError:
    if os.path.isfile(sra_filtered):
        os.rename(sra_filtered, sra_ribodetector_filtered)
    else:
        os.rename(sra_filtered_1, sra_ribodetector_filtered_1)
        os.rename(sra_filtered_2, sra_ribodetector_filtered_2)

I'm getting this message and then stop running:

The command used was: ribodetector_cpu -t 40 -l 101 -e rrna --chunk_size 256 -i /home/apis/vinicius_apis/SRR5117442/SRR5117442_1_filtered.fastq /home/apis/vinicius_apis/SRR5117442/SRR5117442_2_filtered.fastq -o /home/apis/vinicius_apis/SRR5117442/SRR5117442_ribodetector_1.fastq /home/apis/vinicius_apis/SRR5117442/SRR5117442_ribodetector_2.fastq
/usr/bin/bash: line 2: 258719 Killed
0

There are 0 best solutions below