title: multiprocessing error - died with <Signals.SIGKILL: 9>
body: <p>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.</p>
  <p>i wrote script as below.</p>
  <pre><code>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 = [&quot;out1.ps&quot;,&quot;out2.ps&quot;,&quot;out3.ps&quot;,&quot;out4.ps&quot;]
  inp_pdf_list = [&quot;input1.pdf&quot;,&quot;input2.pdf&quot;,&quot;input3.pdf&quot;,&quot;input4.pdf&quot;]
  
  print(&quot;Starting time:{}&quot;.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(&quot;End time:{}&quot;.format(datetime.now()))
  </code></pre>
  <p>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.</p>
  <ol>
  <li><p>CPU utilization is 100% as it is expected. Memory usage is nearly 70-80%.</p>
  </li>
  <li><p>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.</p>
  </li>
  <li><p>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.</p>
  </li>
  <li><p>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.</p>
  </li>
  <li><p>Later, i have added -dDEBUG option in gs command(removed -q) and tried again, getting below trace after 2 hrs.</p>
  <p>Starting time:2020-11-05 09:12:59.074123
  multiprocessing.pool.RemoteTraceback:
  &quot;&quot;&quot;
  Traceback (most recent call last):
  File &quot;/usr/lib64/python3.8/multiprocessing/pool.py&quot;, line 125, in worker
  result = (True, func(*args, **kwds))
  File &quot;/usr/lib64/python3.8/multiprocessing/pool.py&quot;, line 51, in starmapstar
  return list(itertools.starmap(args[0], args[1]))
  File &quot;pdf2ps_gs_poc.py&quot;, line 7, in convert_ps
  check_output(cmd,shell=True)
  File &quot;/usr/lib64/python3.8/subprocess.py&quot;, line 411, in check_output
  return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File &quot;/usr/lib64/python3.8/subprocess.py&quot;, 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 &lt;Signals.SIGKILL: 9&gt;.
  &quot;&quot;&quot;</p>
  <p>The above exception was the direct cause of the following exception:</p>
  <p>Traceback (most recent call last):
  File &quot;pdf2ps_gs_poc.py&quot;, line 14, in 
  return_res = pool.starmap(convert_ps, zip(out_ps_list,inp_pdf_list))
  File &quot;/usr/lib64/python3.8/multiprocessing/pool.py&quot;, line 372, in starmap
  return self._map_async(func, iterable, starmapstar, chunksize).get()
  File &quot;/usr/lib64/python3.8/multiprocessing/pool.py&quot;, 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 &lt;Signals.SIGKILL: 9&gt;.</p>
  </li>
  </ol>
  <p>I have tried with pool.apply_async, but no luck.</p>
  <p>why its killed by sginal kill 9? is there any way to handle in multiprocessing? Someone please help to avoid singal kill 9 error.</p>
  <p>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.</p>