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)
| 21 | |
| 22 | |
| 23 | def 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 | |
| 74 | class TerminalProgressBar: |