Python multiprocessing dies in the middle
<p>I run a <code>python</code> program on <strong>CentOS VPS Server</strong>. I am running this program for last few months &amp; I am facing this problem from the beginning. </p>

<p>I usually run this python program from crontab. The program does the following things everyday sequentially. </p>

<ol>
<li>Connect to a <code>MySQL</code> Database &amp; Update some specific info.</li>
<li>Divide into 8-10 python instances using <code>multiprocessing</code>.</li>
<li>Each instance run virtual display using <code>Xvfb</code> (which is required to run firefox).</li>
<li>Each instance run individual firefox browser. </li>
<li>Every instance visit one website to check update (using <code>selenium</code>) for some data and if it get any changes it update to database.</li>
<li>After checking each instance close <code>firefox</code></li>
</ol>

<p>All these processes usually take 60 min to 90 min if it runs properly. But problem is that it is not running fine every time. Sometime it runs sometimes it dies in the middle. Also I never found any specific reason, why these program dies and what should I do. When I checked <code>top</code> or <code>ps</code>, I found <code>python</code> program is absent and <code>firefox</code> &amp; <code>Xvfb</code> is still there waiting for the python command like a fool. </p>

<p>Probably killed by system due to overload or some other reason. Sometime rebooting system helps. But, I know that is not a good solution. That is why I tried to run the program reducing the niceness value at the lowest level. But, program probably cannot run with negative <code>niceness</code> value, so still the same problem persist.</p>

<pre><code>F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S   500 12673 12655  0  80   0 - 54957 wait   ?        00:00:00 python
1 S   500 12683 12673  0  80   0 - 62766 sk_wai ?        00:00:18 python
1 S   500 12704 12673  0  80   0 - 59295 sk_wai ?        00:00:17 python
1 S   500 12816 12673  0  80   0 - 59230 sk_wai ?        00:00:16 python
1 S   500 12898 12673  0  80   0 - 59400 sk_wai ?        00:00:16 python
1 S   500 12988 12673  0  80   0 - 59491 sk_wai ?        00:00:17 python
1 S   500 13072 12673  0  80   0 - 59151 sk_wai ?        00:00:17 python
</code></pre>

<p>Again, I have run this program on my <strong>Windows 8</strong> desktop and it runs fine with up to 26 instances (I never tried more :) ). As it is running so many instances at a time page loading become slow. That is why I tried to run this program on 3 VPS server by splitting the job.</p>

<p>Also, I run another program using <code>python</code>, <code>firefox</code>, <code>selenium</code>, <code>Xvfb</code> with single process and it runs fine 10-12 hours without any hiccup. Also this program does almost same thing like first one but only difference is it is running only single process. And, it never create any trouble like first one.</p>

<p>Is there any way, which will confirm that it will run the program properly every time?</p>

<p>I have also faced the same problem. After doing a lot of research I concluded, Firefox is not good option for multiprocessing. Better use <strong>PhantomJS</strong> or <strong>Chrome Driver</strong>. In my case when I was saw ps or top, I was getting Zombie Firefox process. </p>

python linux selenium firefox multiprocessing