Skip to content

Commit 9e2c849

Browse files
committed
Fix CustomCluster protocol to work w/ futures again
1 parent 4e67a6b commit 9e2c849

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

mesmerize_core/algorithms/_utils.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,35 @@
66

77
import caiman as cm
88
from caiman.cluster import setup_cluster
9-
from ipyparallel import DirectView
109
from multiprocessing.pool import Pool
1110

1211

12+
RetVal = TypeVar("RetVal")
1313
@runtime_checkable
1414
class CustomCluster(Protocol):
15-
"""Protocol for a cluster that is not a multiprocessing pool"""
16-
RetVal = TypeVar('RetVal')
17-
def map_sync(self, fn: Callable[..., RetVal], args: Iterable) -> Sequence[RetVal]:
18-
...
19-
15+
"""
16+
Protocol for a cluster that is not a multiprocessing pool
17+
(including ipyparallel.DirectView)
18+
"""
19+
20+
def map_sync(
21+
self, fn: Callable[..., RetVal], args: Iterable
22+
) -> Sequence[RetVal]: ...
23+
2024
def __len__(self) -> int:
2125
"""return number of workers"""
2226
...
2327

24-
Cluster = Union[Pool, DirectView, CustomCluster]
28+
29+
Cluster = Union[Pool, CustomCluster]
30+
2531

2632
def get_n_processes(dview: Optional[Cluster]) -> int:
2733
"""Infer number of processes in a multiprocessing or ipyparallel cluster"""
28-
if isinstance(dview, Pool) and hasattr(dview, '_processes'):
34+
if isinstance(dview, Pool):
35+
assert hasattr(dview, '_processes'), "Pool not keeping track of # of processes?"
2936
return dview._processes # type: ignore
30-
elif isinstance(dview, CustomCluster):
37+
elif dview is not None:
3138
return len(dview)
3239
else:
3340
return 1

0 commit comments

Comments
 (0)