code: def create_test_dask_client(
      id: str,
      n_workers: int = 2,
  ) -> Client:
      """Factory to make a Dask client and a function to close it
      them.
  
      Parameters
      ----------
      id: str
          An id to associate with this dask client
  
      n_workers: int = 2
  
      Returns
      -------
      Client
          The client
      """
      # Workers are in subprocesses to not create deadlocks with the pynisher
      # and logging.
      client = Client(
          n_workers=n_workers,
          threads_per_worker=1,
          processes=False,
          scheduler_port=0,  # Set to 0 so it chooses a random one
          dashboard_address=None,  # Disable dashboarding
      )
      adr = client.scheduler_info()["address"]
  
      def close() -> None:
          try:
              client = get_client(adr, timeout=1)
              client.shutdown()
          except Exception:
              pass
  
      active_clients[id] = close
  
      return client
  
file_path: auto-sklearn/test/fixtures/dask.py
imports: from __future__ import annotations
  from typing import Callable
  from functools import partial
  from dask.distributed import Client, get_client
  from pytest import FixtureRequest, fixture
label_desc: Use image node_id 2 for calling a global function with example usage: create_test_dask_client(id, n_workers) and returns: client