worker.kill([signal])


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

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

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

¥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.

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

¥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().

使 .exitedAfterDisconnect 被设置。

¥Causes .exitedAfterDisconnect to be set.

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

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

在一个 worker 中,process.kill() 存在,但不是这个函数;它是 kill()

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