Skip to content

Commit

Permalink
Only override callback methods if present
Browse files Browse the repository at this point in the history
Fixes dask#1125
  • Loading branch information
mrocklin committed Apr 27, 2016
1 parent 5d94595 commit afc9801
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dask/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ class Callback(object):
"""

def __init__(self, start=None, pretask=None, posttask=None, finish=None):
self._start = start
self._pretask = pretask
self._posttask = posttask
self._finish = finish
if start:
self._start = start
if pretask:
self._pretask = pretask
if posttask:
self._posttask = posttask
if finish:
self._finish = finish

@property
def _callback(self):
Expand Down
14 changes: 14 additions & 0 deletions dask/tests/test_callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from dask.async import get_sync
from dask.callbacks import Callback

def test_callback():
flag = [False]

class MyCallback(Callback):
def _start(self, dsk):
flag[0] = True

with MyCallback():
get_sync({'x': 1}, 'x')

assert flag[0] is True

0 comments on commit afc9801

Please sign in to comment.