MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / dask_client_create

Function dask_client_create

pyxrf/core/map_processing.py:23–71  ·  view source on GitHub ↗

Create Dask client object. The function is trivial and introduced so that Dask client is created in uniform way throughout the program. The client is configured to keep temporary data in `~/.dask` directory instead of the current directory. Creating new Dask client may be costl

(**kwargs)

Source from the content-addressed store, hash-verified

21
22
23def dask_client_create(**kwargs):
24 """
25 Create Dask client object. The function is trivial and introduced so that
26 Dask client is created in uniform way throughout the program.
27 The client is configured to keep temporary data in `~/.dask` directory
28 instead of the current directory.
29
30 Creating new Dask client may be costly (a few extra seconds). If computations require
31 multiple calls to functions that are running on Dask, overhead can be reduced by creating
32 one common Dask client and supplying the reference to the client as a parameter in each
33 function call.
34
35 .. code:: python
36
37 client = dask_client_create() # Create Dask client
38 # <-- code that runs computations -->
39 client.close() # Close Dask client
40
41 Parameters
42 ----------
43 kwargs: dict, optional
44 kwargs will be passed to the Dask client constructor. No extra parameters are needed
45 in most cases.
46
47 Returns
48 -------
49 client: dask.distributed.Client
50 Dask client object
51 """
52 _kwargs = {"processes": True, "silence_logs": logging.ERROR}
53 _kwargs.update(kwargs)
54
55 logger.info("Creating Dask Client ...")
56
57 dask.config.set(shuffle="disk")
58
59 current_os = platform.system()
60 if current_os == "Linux":
61 tmp_dir = tempfile.gettempdir()
62 user_name = getpass.getuser()
63 path_dask_data = os.path.join(tmp_dir, user_name, "dask")
64 os.makedirs(path_dask_data, exist_ok=True)
65 else:
66 path_dask_data = os.path.expanduser("~/.dask")
67
68 dask.config.set({"temporary_directory": path_dask_data})
69
70 client = Client(**_kwargs)
71 return client
72
73
74class TerminalProgressBar:

Callers 10

test_dask_client_createFunction · 0.90
_start_dask_clientFunction · 0.90
compute_total_spectrumFunction · 0.85
fit_xrf_mapFunction · 0.85
compute_selected_roisFunction · 0.85
pyxrf_batchFunction · 0.85
_process_xrf_dataFunction · 0.85

Calls 1

updateMethod · 0.80

Tested by 3

test_dask_client_createFunction · 0.72
_start_dask_clientFunction · 0.72