Create a callback with functions of the following signatures:
>>> def start(dsk): ... pass >>> def start_state(dsk, state): ... pass >>> def pretask(key, dsk, state): ... pass >>> def posttask(key, result, dsk, state, worker_id): ... pass >>> def finish(dsk, state, failed): ... pass
You may then construct a callback object with any number of them
>>> cb = Callback(pretask=pretask, finish=finish)
And use it either as a context manager over a compute/get call
>>> with cb: # doctest: +SKIP ... x.compute()
Or globally with the register
method
>>> cb.register() >>> cb.unregister()
Alternatively subclass the Callback
class with your own methods.
>>> class PrintKeys(Callback): ... def _pretask(self, key, dask, state): ... print("Computing: {0}!".format(repr(key)))
>>> with PrintKeys(): # doctest: +SKIP ... x.compute()
Base class for using the callback mechanism
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them