>>> clean_dashboard_address(8787) {'address': '', 'port': 8787} >>> clean_dashboard_address(":8787") {'address': '', 'port': 8787} >>> clean_dashboard_address("8787") {'address': '', 'port': 8787} >>> clean_dashboard_address("8787") {'address': '', 'port': 8787} >>> clean_dashboard_address("foo:8787") {'address': 'foo', 'port': 8787}
The keywords to convert
The callable that consumes these terms to check them for validity
A string with the name of a module, or the module containing a click-generated command with a "main" function, or the function itself. It may be used to parse a module's custom arguments (i.e., arguments that are not part of Worker class), such as nprocs from dask-worker CLI or enable_nvlink from dask-cuda-worker CLI.
>>> cli_keywords({"x": 123, "save_file": "foo.txt"}) ['--x', '123', '--save-file', 'foo.txt'] >>> from dask.distributed import Worker >>> cli_keywords({"x": 123}, Worker) Traceback (most recent call last): ... ValueError: Class distributed.worker.Worker does not support keyword x
String serialied by serialize_for_cli()
The de-serialized data
The object to be converted. Will correctly handled * str * bytes * objects implementing the buffer protocol (memoryview, ndarray, etc.)
When `s` cannot be converted
>>> ensure_bytes('123') b'123' >>> ensure_bytes(b'123') b'123'
>>> ensure_ip('localhost') '127.0.0.1' >>> ensure_ip('123.123.123.123') # pass through IP addresses '123.123.123.123'
*host* defaults to a well-known Internet host (one of Google's public DNS servers).
KeyError is raised if the interface doesn't exist. ValueError is raised if the interface does no have an IPv4 address associated with it.
>>> import_term("math.sin") <function math.sin(x, /)>
>>> is_kernel() False
Will return ``True`` if writeable, ``False`` if readonly, and ``None`` if undetermined.
'x' >>> key_split('x-1') 'x' >>> key_split('x-1-2-3') 'x' >>> key_split(('x-2', 1)) 'x' >>> key_split("('x-2', 1)") 'x' >>> key_split("('x', 1)") 'x' >>> key_split('hello-world-1') 'hello-world' >>> key_split(b'hello-world-1') 'hello-world' >>> key_split('ae05086432ca935f6eba409a8ecd4896') 'data' >>> key_split('<module.submodule.myclass object at 0xdaf372') 'myclass' >>> key_split(None) 'Other' >>> key_split('x-abcdefab') # ignores hex 'x'
>>> key_split_group(('x-2', 1)) 'x-2' >>> key_split_group("('x-2', 1)") 'x-2' >>> key_split_group('ae05086432ca935f6eba409a8ecd4896') 'data' >>> key_split_group('<module.submodule.myclass object at 0xdaf372') 'myclass' >>> key_split_group('x') >>> key_split_group('x-1')
There is a chance that this port will be taken by the operating system soon after returning from this function.
Input port or ports. Can be an integer like 8787, a string for a single port like "8787", a string for a sequential range of ports like "8000:8200", or None.
List of ports
A single port can be specified using an integer: >>> parse_ports(8787) >>> [8787] or a string: >>> parse_ports("8787") >>> [8787] A sequential range of ports can be specified by a string which indicates the first and last ports which should be included in the sequence of ports: >>> parse_ports("8787:8790") >>> [8787, 8788, 8789, 8790] An input of ``None`` is also valid and can be used to indicate that no port has been specified: >>> parse_ports(None) >>> [None]
File-like object supporting seek, read, tell, etc..
Byte offset to start read
Number of bytes to read
Ensure reading starts and stops at delimiter bytestring
>>> from io import BytesIO # doctest: +SKIP >>> f = BytesIO(b'Alice, 100\nBob, 200\nCharlie, 300') # doctest: +SKIP >>> read_block(f, 0, 13) # doctest: +SKIP b'Alice, 100\nBo' >>> read_block(f, 0, 13, delimiter=b'\n') # doctest: +SKIP b'Alice, 100\nBob, 200\n' >>> read_block(f, 10, 10, delimiter=b'\n') # doctest: +SKIP b'Bob, 200\nCharlie, 300'
This seeks the file to the next byte following the delimiter. It does not return anything. Use ``file.tell()`` to see location afterwards. Parameters ---------- file: a file delimiter: bytes a delimiter like ``b' '`` or message sentinel blocksize: int Number of bytes to read from the file at once.
The data to serialize
The serialized data as a string
>>> tokey(b'x') b'x' >>> tokey('x') 'x' >>> tokey(1) '1'
>>> from distributed import Scheduler >>> typename(Scheduler) 'distributed.scheduler.Scheduler'