ray.shutdown#

ray.shutdown(_exiting_interpreter: bool = False)[source]#

Disconnect the worker, and terminate processes started by ray.init().

This will automatically run at the end when a Python process that uses Ray exits. It is ok to run this twice in a row. The primary use case for this function is to cleanup state between tests.

Note that this will clear any remote function definitions, actor definitions, and existing actors, so if you wish to use any previously defined remote functions or actors after calling ray.shutdown(), then you need to redefine them. If they were defined in an imported module, then you will need to reload the module.

Note

The behavior of ray.shutdown() differs depending on how the cluster was initialized:

  • If a new local Ray cluster was started by ray.init() (i.e., no address argument was provided and no existing cluster was found, or address="local" was explicitly used), ray.shutdown() will terminate all the local Ray processes (raylet, object store, etc.) that were spawned by ray.init().

  • If you connected to an existing cluster (e.g., via ray.init(address="auto") or ray.init(address="ray://<ip>:<port>")), ray.shutdown() will only disconnect the client from the cluster. It will not shut down the remote cluster. The cluster will continue running and can be connected to again.

Parameters:

_exiting_interpreter – True if this is called by the atexit hook and false otherwise. If we are exiting the interpreter, we will wait a little while to print any extra error messages.