开始使用免费开始使用

检查集群是否正在运行

我们可以使用 Databricks SDK 中的 clusters 服务来获取指定集群的信息。本练习关注集群的 state,它可以告知我们集群是 Terminated、Idle,还是处于 Running 状态。 假设目标集群的 id 已保存在名为 cluster_id 的变量中。

本练习是课程的一部分

使用 Python SDK 的 Databricks

查看课程

练习说明

  • 获取 cluster_id 变量所保存 id 的集群信息。
  • 打印该集群的状态以确认其正在运行。

交互式实操练习

通过完成这段示例代码来试试这个练习。

w = WorkspaceClient()

# Retrieve info for the specified cluster
cluster_info = w.clusters.____(cluster_id)

# Print the state of the cluster
print(cluster_info.____)
编辑并运行代码