Python multiprocessing - check status of each processes
<p>I wonder if it is possible to check how long of each processes take.<br>
for example, there are four workers and the job should take no more than 10 seconds, but one of worker take more than 10 seconds.Is there way to raise a alert after 10 seconds and before process finish the job. <br>
My initial thought is using manager, but it seems I have wait till process finished.<br>
Many thanks. </p>

<p>You can check whether process is alive after you tried to join it. Don't forget to set timeout otherwise it'll wait until job is finished. </p>

<p>Here is simple example for you </p>

<pre><code>from multiprocessing import Process
import time

def task():
    import time
    time.sleep(5)

procs = []

for x in range(2):
    proc = Process(target=task)
    procs.append(proc)
    proc.start()

time.sleep(2)

for proc in procs:
    proc.join(timeout=0)
    if proc.is_alive():
        print "Job is not finished!"
</code></pre>

python