Skip to content

Commit

Permalink
call finish callbacks on keyboard interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Aug 12, 2015
1 parent 1051efb commit 563a517
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dask/async.py
Expand Up @@ -473,7 +473,11 @@ def fire_task():

# Main loop, wait on tasks to finish, insert new ones
while state['waiting'] or state['ready'] or state['running']:
key, res, tb, worker_id = queue.get()
try:
key, res, tb, worker_id = queue.get()
except KeyboardInterrupt:
for f in finish_cbs:
f(dsk, state, True)
if isinstance(res, Exception):
for f in finish_cbs:
f(dsk, state, True)
Expand Down

4 comments on commit 563a517

@mrocklin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @jcrist

@mrocklin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In particular this lets us Ctrl-C escape out of a computation and not have the progressbar thread continue on the screen

@jcrist
Copy link
Collaborator

@jcrist jcrist commented on 563a517 Aug 12, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps:

try:
    key, res, tb, worker_id = queue.get()
except KeyboardInterrupt as res:
    pass
...

Avoids repeating the cleanup code twice.

Edit: would need the instance check to look for BaseException instead. Just a thought, by no means necessary.

@mrocklin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like my solution here doesn't perform well. This may need some tweaking. I'll try out your solution.

Please sign in to comment.