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


  • signal <string> 发送给工作进程的杀死信号的名称。

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

因为 kill() 会尝试正常地断开工作进程,所以很容易无限期地等待断开连接完成。 例如,如果工作进程进入无限循环,则永远不会发生正常断开连接。 如果不需要正常的断开连接行为,请使用 worker.process.kill()

将导致 .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.

In a worker, process.kill() exists, but it is not this function; it is kill().