<|file_name|>context.py<|end_file_name|><｜fim▁begin｜>"""
Control global computation context
"""

from collections import defaultdict

_globals = defaultdict(lambda: None)
_globals['callbacks'] = set()


class set_options(object):
    """ Set global state within controled context

    This lets you specify various global settings in a tightly controlled with
    block

    Valid keyword arguments currently include:

        get - the scheduler to use
        pool - a thread or process pool
        cache - Cache to use for intermediate results
        func_loads/func_dumps - loads/dumps functions for serialization of data
            likely to contain functions.  Defaults to dill.loads/dill.dumps
        rerun_exceptions_locally - rerun failed tasks in master process<｜fim▁hole｜>    Example
    -------

    >>> with set_options(get=dask.get):  # doctest: +SKIP
    ...     x = np.array(x)  # uses dask.get internally
    """
    def __init__(self, **kwargs):
        self.old = _globals.copy()
        _globals.update(kwargs)

    def __enter__(self):
        return

    def __exit__(self, type, value, traceback):
        _globals.clear()
        _globals.update(self.old)<｜fim▁end｜>