multiprocessing error - died with <Signals.SIGKILL: 9>

Viewed 4138

I am trying to do postscript conversion using ghosctscript with multiprocessing to improve performance as my pdf file is very large in size around 650 mb.

i wrote script as below.

def convert_ps(out_ps,input_pdf):
    cmd = 'gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile={} -f {}'.format(out_ps,input_pdf)
    check_output(cmd,shell=True)

out_ps_list = ["out1.ps","out2.ps","out3.ps","out4.ps"]
inp_pdf_list = ["input1.pdf","input2.pdf","input3.pdf","input4.pdf"]

print("Starting time:{}".format(datetime.now()))
with Pool(processes=4) as pool:
    return_res = pool.starmap(convert_ps, zip(out_ps_list,inp_pdf_list))
pool.join()
print("End time:{}".format(datetime.now()))

when i run ghostscript command for single file, it takes 40 mins to convert pdf to ps as it is 650mb size file. I have 4 core linux machine, OS: RHEL, so i have tried to improve performance by using python multiprocessing. when i run above script, i am facing below issues.

  1. CPU utilization is 100% as it is expected. Memory usage is nearly 70-80%.

  2. After 1.5-2 hrs, server itself goes down, not shutting down, but not at all responding, getting connection time out error when try to open another session. All other application running on same server are goes down, like web applications are gives 500 error which is running on same server.

  3. Now i checked in AWS console for this instance, its shows server is up and running. CPU utilization also less than 10%. But still i can't access the server via SSH/putty.I had to force restart the server via AWS console, then i can access the server.

  4. When i checked, ghostscript posctscript conversion process, its stopped without completing all 4 workers. Some time, 2 files got generated out of 4, some time none.

  5. Later, i have added -dDEBUG option in gs command(removed -q) and tried again, getting below trace after 2 hrs.

    Starting time:2020-11-05 09:12:59.074123 multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "/usr/lib64/python3.8/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 51, in starmapstar return list(itertools.starmap(args[0], args[1])) File "pdf2ps_gs_poc.py", line 7, in convert_ps check_output(cmd,shell=True) File "/usr/lib64/python3.8/subprocess.py", line 411, in check_output return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/lib64/python3.8/subprocess.py", line 512, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command 'gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=out4.ps -f Loop_Five_Thousand4.pdf' died with <Signals.SIGKILL: 9>. """

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last): File "pdf2ps_gs_poc.py", line 14, in return_res = pool.starmap(convert_ps, zip(out_ps_list,inp_pdf_list)) File "/usr/lib64/python3.8/multiprocessing/pool.py", line 372, in starmap return self._map_async(func, iterable, starmapstar, chunksize).get() File "/usr/lib64/python3.8/multiprocessing/pool.py", line 768, in get raise self._value subprocess.CalledProcessError: Command 'gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=out4.ps -f Loop_Five_Thousand4.pdf' died with <Signals.SIGKILL: 9>.

I have tried with pool.apply_async, but no luck.

why its killed by sginal kill 9? is there any way to handle in multiprocessing? Someone please help to avoid singal kill 9 error.

EDIT: Observed that, whenever RAM memory utilization goes to 97-98%, server goes down after killing the long running process. Could not find any logs related to OOM issue in /var/log/message. Reduced running no.of process to fix the issue.

0 Answers
Related