Skip to content

Commit

Permalink
Create thread state within dask/base.py
Browse files Browse the repository at this point in the history
dask/distributed will now use this thread_state by default
  • Loading branch information
mrocklin committed Oct 12, 2017
1 parent 1733a54 commit af54fbd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dask/__init__.py
Expand Up @@ -8,7 +8,7 @@
except ImportError:
pass
try:
from .base import visualize, compute, persist
from .base import visualize, compute, persist, thread_state
except ImportError:
pass

Expand Down
7 changes: 5 additions & 2 deletions dask/base.py
Expand Up @@ -24,6 +24,9 @@
__all__ = ("Base", "compute", "normalize_token", "tokenize", "visualize")


thread_state = threading.local()


class Base(object):
"""Base class for dask collections"""
__slots__ = ()
Expand Down Expand Up @@ -193,7 +196,7 @@ def compute(*args, **kwargs):

get = kwargs.pop('get', None) or _globals['get']

if get is None and _globals.get('distributed_worker'):
if get is None and getattr(thread_state, 'key', False):
from distributed.worker import get_worker
get = get_worker().client.get

Expand Down Expand Up @@ -558,7 +561,7 @@ def persist(*args, **kwargs):

get = kwargs.pop('get', None) or _globals['get']

if get is None and _globals.get('distributed_worker'):
if get is None and getattr(thread_state, 'key', False):
from distributed.worker import get_worker
get = get_worker().client.get

Expand Down
2 changes: 2 additions & 0 deletions docs/source/changelog.rst
Expand Up @@ -24,6 +24,8 @@ Core
++++

- Allow tuples as sharedict keys (:pr:`2763`)
- Calling compute within a dask.distributed task defaults to distributed
scheduler (:pr:`2762`)

0.15.4 / 2017-10-06
-------------------
Expand Down

0 comments on commit af54fbd

Please sign in to comment.