# Path: mapchete/errors.py
# class JobCancelledError(Exception):
#     """Raised when Job gets cancelled."""
# 
# Path: mapchete/log.py
# def set_log_level(loglevel):
#     stream_handler.setLevel(loglevel)
#     for i in all_mapchete_packages:
#         logging.getLogger(i).setLevel(loglevel)
# 
# Path: mapchete/_timer.py
# class Timer:
#     """
#     Context manager to facilitate timing code.
# 
#     Examples
#     --------
#     >>> with Timer() as t:
#             ...  # some longer running code
#     >>> print(t)  # prints elapsed time
# 
#     based on http://preshing.com/20110924/timing-your-code-using-pythons-with-statement/
#     """
# 
#     def __init__(self, elapsed=0.0, str_round=3):
#         self._elapsed = elapsed
#         self._str_round = str_round
#         self.start = None
#         self.end = None
# 
#     def __enter__(self):
#         self.start = time.time()
#         return self
# 
#     def __exit__(self, *args):
#         self.end = time.time()
#         self._elapsed = self.end - self.start
# 
#     def __lt__(self, other):
#         return self._elapsed < other._elapsed
# 
#     def __le__(self, other):
#         return self._elapsed <= other._elapsed
# 
#     def __eq__(self, other):
#         return self._elapsed == other._elapsed
# 
#     def __ne__(self, other):
#         return self._elapsed != other._elapsed
# 
#     def __ge__(self, other):
#         return self._elapsed >= other._elapsed
# 
#     def __gt__(self, other):
#         return self._elapsed > other._elapsed
# 
#     def __add__(self, other):
#         return Timer(elapsed=self._elapsed + other._elapsed)
# 
#     def __sub__(self, other):
#         return Timer(elapsed=self._elapsed - other._elapsed)
# 
#     def __repr__(self):
#         return "Timer(start=%s, end=%s, elapsed=%s)" % (
#             self.start,
#             self.end,
#             self.__str__(),
#         )
# 
#     def __str__(self):
#         minutes, seconds = divmod(self.elapsed, 60)
#         hours, minutes = divmod(minutes, 60)
#         if hours:
#             return "%sh %sm %ss" % (int(hours), int(minutes), int(seconds))
#         elif minutes:
#             return "%sm %ss" % (int(minutes), int(seconds))
#         else:
#             return "%ss" % round(seconds, self._str_round)
# 
#     @property
#     def elapsed(self):
#         return (
#             time.time() - self.start if self.start and not self.end else self._elapsed
#         )


import concurrent.futures
import logging
import multiprocessing
import os
import sys
import warnings
from concurrent.futures._base import CancelledError
from functools import partial
from cached_property import cached_property
from mapchete.errors import JobCancelledError
from mapchete.log import set_log_level
from mapchete._timer import Timer
        from dask.distributed import as_completed, Client, LocalCluster
        from dask.distributed import wait
        from dask.distributed import TimeoutError
        from dask.distributed import TimeoutError
        from distributed.comm.core import CommClosedError
                self._executor.close()
            except Exception:  # pragma: no cover
                self._executor.__exit__(*args)
            logger.info("closed executor %s", self._executor)
        if self._local_cluster:
            logger.info("closing %s", self._local_cluster)
            self._local_cluster.close()


class ConcurrentFuturesExecutor(_ExecutorBase):
    """Execute tasks using concurrent.futures."""

    def __init__(
        self,
        *args,
        max_workers=None,
        concurrency="processes",
        multiprocessing_start_method=None,
        **kwargs,
    ):
        """Set attributes."""
        start_method = (
            multiprocessing_start_method or MULTIPROCESSING_DEFAULT_START_METHOD
        )
        self.max_workers = max_workers or os.cpu_count()
        self._executor_kwargs = dict(
            max_workers=self.max_workers,
        )
        if sys.version_info >= (3, 7):
            self._executor_kwargs.update(

# Path: mapchete/errors.py
# class JobCancelledError(Exception):
#     """Raised when Job gets cancelled."""
# 
# Path: mapchete/log.py
# def set_log_level(loglevel):
#     stream_handler.setLevel(loglevel)
#     for i in all_mapchete_packages:
#         logging.getLogger(i).setLevel(loglevel)
# 
# Path: mapchete/_timer.py
# class Timer:
#     """
#     Context manager to facilitate timing code.
# 
#     Examples
#     --------
#     >>> with Timer() as t:
#             ...  # some longer running code
#     >>> print(t)  # prints elapsed time
# 
#     based on http://preshing.com/20110924/timing-your-code-using-pythons-with-statement/
#     """
# 
#     def __init__(self, elapsed=0.0, str_round=3):
#         self._elapsed = elapsed
#         self._str_round = str_round
#         self.start = None
#         self.end = None
# 
#     def __enter__(self):
#         self.start = time.time()
#         return self
# 
#     def __exit__(self, *args):
#         self.end = time.time()
#         self._elapsed = self.end - self.start
# 
#     def __lt__(self, other):
#         return self._elapsed < other._elapsed
# 
#     def __le__(self, other):
#         return self._elapsed <= other._elapsed
# 
#     def __eq__(self, other):
#         return self._elapsed == other._elapsed
# 
#     def __ne__(self, other):
#         return self._elapsed != other._elapsed
# 
#     def __ge__(self, other):
#         return self._elapsed >= other._elapsed
# 
#     def __gt__(self, other):
#         return self._elapsed > other._elapsed
# 
#     def __add__(self, other):
#         return Timer(elapsed=self._elapsed + other._elapsed)
# 
#     def __sub__(self, other):
#         return Timer(elapsed=self._elapsed - other._elapsed)
# 
#     def __repr__(self):
#         return "Timer(start=%s, end=%s, elapsed=%s)" % (
#             self.start,
#             self.end,
#             self.__str__(),
#         )
# 
#     def __str__(self):
#         minutes, seconds = divmod(self.elapsed, 60)
#         hours, minutes = divmod(minutes, 60)
#         if hours:
#             return "%sh %sm %ss" % (int(hours), int(minutes), int(seconds))
#         elif minutes:
#             return "%sm %ss" % (int(minutes), int(seconds))
#         else:
#             return "%ss" % round(seconds, self._str_round)
# 
#     @property
#     def elapsed(self):
#         return (
#             time.time() - self.start if self.start and not self.end else self._elapsed
#         )


# Path: mapchete/_executor.py
import concurrent.futures
import logging
import multiprocessing
import os
import sys
import warnings
from concurrent.futures._base import CancelledError
from functools import partial
from cached_property import cached_property
from mapchete.errors import JobCancelledError
from mapchete.log import set_log_level
from mapchete._timer import Timer
        from dask.distributed import as_completed, Client, LocalCluster
        from dask.distributed import wait
        from dask.distributed import TimeoutError
        from dask.distributed import TimeoutError
        from distributed.comm.core import CommClosedError

                self._executor.close()
            except Exception:  # pragma: no cover
                self._executor.__exit__(*args)
            logger.info("closed executor %s", self._executor)
        if self._local_cluster:
            logger.info("closing %s", self._local_cluster)
            self._local_cluster.close()


class ConcurrentFuturesExecutor(_ExecutorBase):
    """Execute tasks using concurrent.futures."""

    def __init__(
        self,
        *args,
        max_workers=None,
        concurrency="processes",
        multiprocessing_start_method=None,
        **kwargs,
    ):
        """Set attributes."""
        start_method = (
            multiprocessing_start_method or MULTIPROCESSING_DEFAULT_START_METHOD
        )
        self.max_workers = max_workers or os.cpu_count()
        self._executor_kwargs = dict(
            max_workers=self.max_workers,
        )
        if sys.version_info >= (3, 7):
            self._executor_kwargs.update(

                initializer=set_log_level,