python multiprocessing pool terminate

后端 未结 4 1698
攒了一身酷
攒了一身酷 2020-12-23 23:14

I\'m working on a renderfarm, and I need my clients to be able to launch multiple instances of a renderer, without blocking so the client can receive new commands. I\'ve got

4条回答
  •  离开以前
    2020-12-23 23:47

    I found solution: stop pool in separate thread, like this:

    def close_pool():
        global pool
        pool.close()
        pool.terminate()
        pool.join()
    
    def term(*args,**kwargs):
        sys.stderr.write('\nStopping...')
        # httpd.shutdown()
        stophttp = threading.Thread(target=httpd.shutdown)
        stophttp.start()
        stoppool=threading.Thread(target=close_pool)
        stoppool.daemon=True
        stoppool.start()
    
    
    signal.signal(signal.SIGTERM, term)
    signal.signal(signal.SIGINT, term)
    signal.signal(signal.SIGQUIT, term)
    

    Works fine and always i tested.

    signal.SIGINT
    

    Interrupt from keyboard (CTRL + C). Default action is to raise KeyboardInterrupt.

    signal.SIGKILL
    

    Kill signal. It cannot be caught, blocked, or ignored.

    signal.SIGTERM
    

    Termination signal.

    signal.SIGQUIT
    

    Quit with core dump.

提交回复
热议问题