MCPcopy Create free account
hub / github.com/dask/dask / add_callbacks

Class add_callbacks

dask/callbacks.py:120–145  ·  view source on GitHub ↗

Context manager for callbacks. Takes several callbacks and applies them only in the enclosed context. Callbacks can either be represented as a ``Callback`` object, or as a tuple of length 4. Examples -------- >>> def pretask(key, dsk, state): ... print("Now running

Source from the content-addressed store, hash-verified

118
119
120class add_callbacks:
121 """Context manager for callbacks.
122
123 Takes several callbacks and applies them only in the enclosed context.
124 Callbacks can either be represented as a ``Callback`` object, or as a tuple
125 of length 4.
126
127 Examples
128 --------
129 >>> def pretask(key, dsk, state):
130 ... print("Now running {0}").format(key)
131 >>> callbacks = (None, pretask, None, None)
132 >>> with add_callbacks(callbacks): # doctest: +SKIP
133 ... res.compute()
134 """
135
136 def __init__(self, *callbacks):
137 self.callbacks = [normalize_callback(c) for c in callbacks]
138 Callback.active.update(self.callbacks)
139
140 def __enter__(self):
141 return
142
143 def __exit__(self, type, value, traceback):
144 for c in self.callbacks:
145 Callback.active.discard(c)

Callers 1

__enter__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected