worker.kill([signal='SIGTERM'])


  • signal <string> 被发送kill信号的工作进程名称。

这个方法将会kill工作进程。在主进程中,通过断开与worker.process的连接来实现,一旦断开连接后,通过signal来杀死工作进程。在工作进程中,通过断开IPC管道来实现,然后以代码0退出进程。

将导致.exitedAfterDisconnect被设置。

为向后兼容,这个方法与worker.destroy()等义。

需要注意的是,在工作进程中有一个方法process.kill() ,这个方法与本方法不同,本方法是kill

  • signal <string> Name of the kill signal to send to the worker process.

This function will kill the worker. In the master, it does this by disconnecting the worker.process, and once disconnected, killing with signal. In the worker, it does it by disconnecting the channel, and then exiting with code 0.

Because kill() attempts to gracefully disconnect the worker process, it is susceptible to waiting indefinitely for the disconnect to complete. For example, if the worker enters an infinite loop, a graceful disconnect will never occur. If the graceful disconnect behavior is not needed, use worker.process.kill().

Causes .exitedAfterDisconnect to be set.

This method is aliased as worker.destroy() for backwards compatibility.

Note that in a worker, process.kill() exists, but it is not this function, it is kill.