worker.kill([signal])


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

此函数将终止工作线程。在主工作线程中,它通过断开 worker.process 来实现,一旦断开连接,就使用 signal 进行终止。在工作线程中,它通过使用 signal 终止进程来实现。

【This function will kill the worker. In the primary worker, it does this by disconnecting the worker.process, and once disconnected, killing with signal. In the worker, it does it by killing the process with signal.】

kill() 函数会立即终止工作进程,而不会等待正常断开,它的行为与 worker.process.kill() 相同。

【The kill() function kills the worker process without waiting for a graceful disconnect, it has the same behavior as worker.process.kill().】

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

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

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

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