Skip to content

Commit

Permalink
Clean up get on Client._close
Browse files Browse the repository at this point in the history
  • Loading branch information
mrocklin committed Nov 2, 2017
1 parent 47f990f commit 51111bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions distributed/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,12 @@ def _handle_error(self, exception=None):
def _close(self, fast=False):
""" Send close signal and wait until scheduler completes """
with log_errors():
with ignoring(AttributeError):
dask.set_options(get=self._previous_get)
with ignoring(AttributeError):
dask.set_options(shuffle=self._previous_shuffle)
if self.get == _globals.get('get'):
del _globals['get']
if self.status == 'closed':
raise gen.Return()
if self.scheduler_comm and self.scheduler_comm.comm and not self.scheduler_comm.comm.closed():
Expand Down
13 changes: 13 additions & 0 deletions distributed/tests/test_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def test_gen_cluster(c, s, a, b):
assert s.ncores == {w.address: w.ncores for w in [a, b]}


def test_gen_cluster_cleans_up_client():
import dask.context
assert not dask.context._globals.get('get')

@gen_cluster(client=True)
def f(c, s, a, b):
pass

f()

assert not dask.context._globals.get('get')


@gen_cluster(client=False)
def test_gen_cluster_without_client(s, a, b):
assert isinstance(s, Scheduler)
Expand Down

0 comments on commit 51111bc

Please sign in to comment.