ShanN
ShanN

Reputation: 943

How to manage the python process when using multiprocess method

I have a problem when using multiprocessing in Python. One of my processes stops silently. How to get the signal and restart it automatically.

My code is as below. the p0 stops silently without any warning after hours of running. I have tried using is_alive() but still do not know how to put it in the right flow to restart whenever the process down.

def func_15():
    while 1:
        get_data
        send_data
...

if __name__ == '__main__':
    logging.info('===========PROCESS BEGIN================')
    
    logging.info('TIME15 - CREATING PROCESS')
    p0 = Process(target = func_15m, args = ())
    
    logging.info('TIME1 - CREATING PROCESS')
    p1 = Process(target = func_1h, args = ())
    
    logging.info('TIME4 - CREATING PROCESS')
    p2 = Process(target = func_4h, args = ())
    
    p0.start()
    p1.start()
    p2.start()
    
    p0.join()
    p1.join()
    p2.join()

Please help! Thanks so much!

Upvotes: 0

Views: 102

Answers (1)

Marc
Marc

Reputation: 1629

Take a look at this question Python Multiprocessing: Handling Child Errors in Parent and it’s answers.

If I were you I would first implement a manner to see what is making the loop exit, so make the exception Propagate to the parent process. (Or simply wrap the whole loop in a try catch and Print the exception when caught). Then you can figure out if it is something you can fix within your function. Besides that there are explanations on what to do when you want the process to restart when the process stops.

Upvotes: 1

Related Questions