how to to terminate process using python's multiprocessing

前端 未结 3 1934
你的背包
你的背包 2020-12-14 02:56

I have some code that needs to run against several other systems that may hang or have problems not under my control. I would like to use python\'s multiprocessing to spawn

3条回答
  •  爱一瞬间的悲伤
    2020-12-14 03:23

    The way Python multiprocessing handles processes is a bit confusing.

    From the multiprocessing guidelines:

    Joining zombie processes

    On Unix when a process finishes but has not been joined it becomes a zombie. There should never be very many because each time a new process starts (or active_children() is called) all completed processes which have not yet been joined will be joined. Also calling a finished process’s Process.is_alive will join the process. Even so it is probably good practice to explicitly join all the processes that you start.

    In order to avoid a process to become a zombie, you need to call it's join() method once you kill it.

    If you want a simpler way to deal with the hanging calls in your system you can take a look at pebble.

提交回复
热议问题