7

I want to start a local cluster from python with a specific number of workers, and then connect a client to it.

cluster = LocalCluster(n_workers=8, ip='127.0.0.1')
client = Client(cluster)

But before, I want to check if there is an existing local cluster, started for example by the dask-scheduler command. Is there a way to do this ?

medRa
  • 73
  • 1
  • 4

1 Answers1

7

There is no standard convention to check if a scheduler exists on your machine. The best you can do is try with a short timeout. The default port is 8786

from dask.distributed import Client, TimeoutError

try:
    client = Client('tcp://localhost:8786', timeout='2s')
except TimeoutError:
    pass
MRocklin
  • 55,641
  • 23
  • 163
  • 235