Skip to content

Commit

Permalink
Create executors lazily in Spec
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwhite committed Feb 19, 2025
1 parent 21ed79a commit 6724df2
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions cubed/spec.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from functools import lru_cache
from functools import cached_property, lru_cache
from typing import Optional, Union

import donfig
Expand Down Expand Up @@ -60,14 +60,9 @@ def __init__(
else:
self._allowed_mem = convert_to_bytes(allowed_mem)

self._executor: Optional[Executor]
if executor is not None:
self._executor = executor
elif executor_name is not None:
self._executor = create_executor(executor_name, executor_options)
else:
self._executor = None

self._executor = executor
self._executor_name = executor_name
self._executor_options = executor_options
self._storage_options = storage_options
self._zarr_compressor = zarr_compressor

Expand Down Expand Up @@ -96,10 +91,22 @@ def reserved_mem(self) -> int:
"""
return self._reserved_mem

@property
@cached_property
def executor(self) -> Optional[Executor]:
"""The default executor for running computations."""
return self._executor
if self._executor is not None:
return self._executor
elif self.executor_name is not None:
return create_executor(self.executor_name, self.executor_options)
return None

@property
def executor_name(self) -> Optional[str]:
return self._executor_name

@property
def executor_options(self) -> Optional[dict]:
return self._executor_options

@property
def storage_options(self) -> Optional[dict]:
Expand Down

0 comments on commit 6724df2

Please sign in to comment.