worker.kill([signal])


  • signal <string> 发送给工作进程的终止信号的名称。 默认值: 'SIGTERM'

此函数会杀死工作进程。 在主进程中,它通过断开 worker.process 来实现这一点,一旦断开连接,就使用 signal 杀死。 在工作进程中,它通过断开通道来完成,然后以代码 0 退出。

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

使 .exitedAfterDisconnect 被设置。

为了向后兼容,此方法别名为 worker.destroy()

在工作进程中,process.kill() 是存在的,但不是这个函数;它是 kill()

  • signal <string> Name of the kill signal to send to the worker process. Default: 'SIGTERM'

This function will kill the worker. In the primary, 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 backward compatibility.

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